-
Notifications
You must be signed in to change notification settings - Fork 0
Hw2/team2 #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Hw2/team2 #11
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| using System.Runtime.InteropServices.JavaScript; | ||
| using FluentAssertions; | ||
| using TDDLesson; | ||
|
|
||
| namespace TestProject1; | ||
|
|
||
| [TestClass] | ||
| public class NotificationServiceTests | ||
| { | ||
| [TestMethod] | ||
| public void ShouldReturnNull_WhenEmployeesNotSaved() | ||
| { | ||
| var notificationRequest = new NotificationRequest( | ||
| false, | ||
| 99, | ||
| new DateTime(2024, 07, 01), | ||
| "[email protected]"); | ||
|
|
||
| var emailDto = NotificationService.CreateNotification(notificationRequest); | ||
|
|
||
| emailDto.Should().BeNull(); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void ShouldReturnNull_WhenDataNotInInterval() | ||
| { | ||
| var notificationRequest = new NotificationRequest( | ||
| true, | ||
| 101, | ||
| new DateTime(1990, 07, 01), | ||
| "[email protected]"); | ||
|
|
||
| var emailDto = NotificationService.CreateNotification(notificationRequest); | ||
|
|
||
| emailDto.Should().BeNull(); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| public void ShouldReturnEmailDto_WhenCorrectData() | ||
| { | ||
| var notificationRequest = new NotificationRequest( | ||
| true, | ||
| 101, | ||
| new DateTime(2024, 07, 01), | ||
| "[email protected]"); | ||
|
|
||
| var emailDto = NotificationService.CreateNotification(notificationRequest); | ||
|
|
||
| emailDto.Should().NotBeNull(); | ||
|
Comment on lines
+47
to
+49
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ну тут ассертик недостаточный, но думаю, вы просто углы срезали :) |
||
| } | ||
|
|
||
| [TestMethod] | ||
| public void ShouldReturnEmailDtoWithoutInvite_WhenCorrectDataAndLess500Employee() | ||
| { | ||
| var notificationRequest = new NotificationRequest( | ||
| true, | ||
| 150, | ||
| new DateTime(2024, 07, 01), | ||
| "[email protected]"); | ||
|
|
||
| var emailDto = NotificationService.CreateNotification(notificationRequest); | ||
|
|
||
| emailDto.Should().NotBeNull(); | ||
| emailDto.MailTo.Should().Be("[email protected]"); | ||
| emailDto.Subject.Should().Be(NotificationService.Subject); | ||
| emailDto.Body.Should().Be(NotificationService.ProcessedMessage); | ||
|
|
||
| } | ||
|
|
||
| [TestMethod] | ||
| public void ShouldReturnEmailDtoWithInvite_WhenCorrectDataAndMore500Employee() | ||
| { | ||
| var notificationRequest = new NotificationRequest( | ||
| true, | ||
| 550, | ||
| new DateTime(2024, 07, 01), | ||
| "[email protected]"); | ||
|
|
||
| var emailDto = NotificationService.CreateNotification(notificationRequest); | ||
|
|
||
| emailDto.Should().NotBeNull(); | ||
| emailDto.MailTo.Should().Be("[email protected]"); | ||
| emailDto.Subject.Should().Be(NotificationService.Subject); | ||
| emailDto.Body.Should().Be(NotificationService.ProcessedMessage + " " + NotificationService.InviteMessage); | ||
|
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| using FluentAssertions; | ||
| using TDDLesson; | ||
|
|
||
| namespace TestProject1; | ||
|
|
||
| [TestClass] | ||
| public class ProposalValidatorTests | ||
| { | ||
| [TestMethod] | ||
| public void ShouldBeValid_WhenEmployeesAndRevenueInCorrectInterval() | ||
| { | ||
| var request = new ProposalValidationRequest(101, 31); | ||
|
|
||
| var result = ProposalValidator.IsProposalValid(request); | ||
|
|
||
| result.Should().BeTrue(); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| [DataRow(100)] | ||
| [DataRow(50)] | ||
| public void ShouldBeInvalid_WhenEmployeesNumberLessThan100(int employeeAmount) | ||
| { | ||
| var request = new ProposalValidationRequest(employeeAmount, 31); | ||
|
|
||
| var result = ProposalValidator.IsProposalValid(request); | ||
|
|
||
| result.Should().BeFalse(); | ||
| } | ||
|
|
||
| [TestMethod] | ||
| [DataRow(30)] | ||
| [DataRow(15)] | ||
| public void ShouldBeInvalid_WhenRevenueAmountLessThan30(int itRevenuePercent) | ||
| { | ||
| var request = new ProposalValidationRequest(101, itRevenuePercent); | ||
|
|
||
| var result = ProposalValidator.IsProposalValid(request); | ||
|
|
||
| result.Should().BeFalse(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,15 +4,59 @@ public class AccreditationProposalProcessor | |
| { | ||
| private readonly IRevenueService _revenueService; | ||
| private readonly IRepository _orderRepository; | ||
| private readonly IEmailClient _emailClient; | ||
|
|
||
| public AccreditationProposalProcessor(IRevenueService revenueService, IRepository orderRepository) | ||
| public AccreditationProposalProcessor(IRevenueService revenueService, IRepository orderRepository, IEmailClient emailClient) | ||
| { | ||
| _revenueService = revenueService; | ||
| _orderRepository = orderRepository; | ||
| _emailClient = emailClient; | ||
| } | ||
|
|
||
| public async Task HandleProposal(ProposalDto dto) | ||
| { | ||
| var itRevenuePercent = _revenueService.GetRevenuePercent(dto.CompanyNumber); | ||
| var proposalValidationRequest = new ProposalValidationRequest( | ||
| EmployeesAmount: dto.EmployeesAmount, | ||
| ItRevenuePercent: itRevenuePercent | ||
| ); | ||
|
|
||
| var valid = ProposalValidator.IsProposalValid(proposalValidationRequest); | ||
|
|
||
| if (!valid) | ||
| return; | ||
|
|
||
| var saved = false; | ||
| try | ||
| { | ||
| await _orderRepository.SaveAsync(new ProposalData | ||
| { | ||
| CompanyEmail = dto.CompanyEmail, | ||
| CompanyName = dto.CompanyName, | ||
| CompanyNumber = dto.CompanyNumber, | ||
| EmployeesAmount = dto.EmployeesAmount | ||
| }); | ||
|
|
||
| saved = true; | ||
| } | ||
| catch (Exception e) | ||
| { | ||
| } | ||
|
Comment on lines
+29
to
+44
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Вы тут немного перемудрили с try-catch и saved. Лучше отказы инфраструктуры в бизнес-логику не встраивать (как это у вас в При этом в самом коде будет чистое-бизнесовое:
|
||
|
|
||
|
|
||
| var notificationRequest = new NotificationRequest( | ||
| Saved: saved, | ||
| EmployeesNumber: dto.EmployeesAmount, | ||
| HandleDate: DateTime.UtcNow, | ||
| MailTo: dto.CompanyEmail); | ||
|
|
||
| var emailDto = NotificationService.CreateNotification(notificationRequest); | ||
|
|
||
| if (emailDto != null) | ||
| await _emailClient.SendEmail( | ||
| mailTo: emailDto.MailTo, | ||
| subject: emailDto.Subject, | ||
| body: emailDto.Body); | ||
|
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| namespace TDDLesson; | ||
|
|
||
| public record EmailDto(string MailTo, string Subject, string Body); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| namespace TDDLesson; | ||
|
|
||
| public record NotificationRequest(bool Saved, int EmployeesNumber, DateTime HandleDate, string MailTo); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| namespace TDDLesson; | ||
|
|
||
| public static class NotificationService | ||
| { | ||
| public const string Subject = "Proposal info."; | ||
| public const string ProcessedMessage = "Proposal processed."; | ||
| public const string InviteMessage = "We invite you to the forum on the development of the IT industry."; | ||
|
|
||
| public static EmailDto? CreateNotification(NotificationRequest request) | ||
| { | ||
| if (request.HandleDate < new DateTime(2024, 06, 01) || request.HandleDate > new DateTime(2024, 09, 01)) | ||
| { | ||
| return null; | ||
| } | ||
| if (request.EmployeesNumber <= 100) | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| var body = request.EmployeesNumber <= 500 ? ProcessedMessage : ProcessedMessage + " " + InviteMessage; | ||
| return new EmailDto(request.MailTo, Subject, body); | ||
| } | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| namespace TDDLesson; | ||
|
|
||
| public class ProposalData | ||
| { | ||
| public required int CompanyNumber { get; set; } | ||
|
|
||
| public required string CompanyName { get; set; } | ||
|
|
||
| public required string CompanyEmail { get; set; } | ||
|
|
||
| public required int EmployeesAmount { get; set; } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| namespace TDDLesson; | ||
|
|
||
| public record ProposalValidationRequest(int EmployeesAmount, float ItRevenuePercent); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| namespace TDDLesson; | ||
|
|
||
| public static class ProposalValidator | ||
| { | ||
| public static bool IsProposalValid(ProposalValidationRequest proposalValidationRequest) | ||
| { | ||
| if (proposalValidationRequest.EmployeesAmount <= 100) | ||
| return false; | ||
|
|
||
| if (proposalValidationRequest.ItRevenuePercent <= 30) | ||
| return false; | ||
|
|
||
| return true; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| <wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> | ||
| <s:Int64 x:Key="/Default/Environment/Hierarchy/Build/BuildTool/MsbuildVersion/@EntryValue">4294967293</s:Int64> | ||
| <s:String x:Key="/Default/Environment/Hierarchy/Build/BuildTool/CustomBuildToolPath/@EntryValue">/usr/local/share/dotnet/sdk/8.0.203/MSBuild.dll</s:String> | ||
| <s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=46c725ae_002Dcc42_002D4ccd_002Db699_002Df44f04a3f20a/@EntryIndexedValue"><SessionState ContinuousTestingMode="0" IsActive="True" Name="All tests from Solution" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session">
 | ||
| <Solution />
 | ||
| </SessionState></s:String></wpf:ResourceDictionary> | ||
|
|
||
|
|
||
|
|
||
| </wpf:ResourceDictionary> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Не совсем бизнесовый нейминг: бизнес не знает, что такое дто. Бизнес не знает, что значит Return.
Представьте, что вы название теста транслируете вашему ПМ-у или какому-нибудь менеджеру из m1/m2. Поймут ли они перевод?
А вот если будет, например,
ShouldCreateNotification_When.. - как будто уже и понятнее
или
ShouldNotCreateNotification
ShouldFail
ShouldCreateNothing
в общем, приветствуются термины бизнеса, а не термины из языка программирования (Return/False/True/Null/etc)