This commit is contained in:
2025-04-15 15:20:49 +04:00
parent c692f50d0d
commit 00a8846f33
7 changed files with 50 additions and 50 deletions

View File

@@ -64,7 +64,7 @@ public class SalaryBusinessLogicContract(ISalaryStorageContract salaryStorageCon
var salary = post.ConfigurationModel switch
{
null => 0,
ManagerPostConfiguration cpc => CalculateSalaryForTravelAgent(sales, startDate, finishDate, cpc),
ManagerPostConfiguration cpc => CalculateSalaryForSuperManager(sales, startDate, finishDate, cpc),
BakerPostConfiguration spc => CalculateSalaryForChief(startDate, finishDate, spc),
PostConfiguration pc => pc.Rate,
};
@@ -72,7 +72,7 @@ public class SalaryBusinessLogicContract(ISalaryStorageContract salaryStorageCon
_salaryStorageContract.AddElement(new SalaryDataModel(employee.Id, finishDate, salary));
}
}
private double CalculateSalaryForTravelAgent(List<SaleDataModel> sales, DateTime startDate, DateTime finishDate, ManagerPostConfiguration config)
private double CalculateSalaryForSuperManager(List<SaleDataModel> sales, DateTime startDate, DateTime finishDate, ManagerPostConfiguration config)
{
var calcPercent = 0.0;
var dates = new List<DateTime>();

View File

@@ -39,9 +39,9 @@ internal class PostBusinessLogicContractTests
//Arrange
var listOriginal = new List<PostDataModel>()
{
new(Guid.NewGuid().ToString(),"name 1", PostType.TravelAgent, new PostConfiguration() { Rate = 10 }),
new(Guid.NewGuid().ToString(), "name 2", PostType.TravelAgent, new PostConfiguration() { Rate = 10 }),
new(Guid.NewGuid().ToString(), "name 3", PostType.TravelAgent, new PostConfiguration() { Rate = 10 }),
new(Guid.NewGuid().ToString(),"name 1", PostType.SuperManager, new PostConfiguration() { Rate = 10 }),
new(Guid.NewGuid().ToString(), "name 2", PostType.SuperManager, new PostConfiguration() { Rate = 10 }),
new(Guid.NewGuid().ToString(), "name 3", PostType.SuperManager, new PostConfiguration() { Rate = 10 }),
};
_postStorageContract.Setup(x => x.GetList()).Returns(listOriginal);
//Act
@@ -95,8 +95,8 @@ internal class PostBusinessLogicContractTests
var postId = Guid.NewGuid().ToString();
var listOriginal = new List<PostDataModel>()
{
new(postId, "name 1", PostType.TravelAgent, new PostConfiguration() { Rate = 10 }),
new(postId, "name 2", PostType.TravelAgent, new PostConfiguration() { Rate = 10 })
new(postId, "name 1", PostType.SuperManager, new PostConfiguration() { Rate = 10 }),
new(postId, "name 2", PostType.SuperManager, new PostConfiguration() { Rate = 10 })
};
_postStorageContract.Setup(x => x.GetPostWithHistory(It.IsAny<string>())).Returns(listOriginal);
//Act
@@ -160,7 +160,7 @@ internal class PostBusinessLogicContractTests
{
//Arrange
var id = Guid.NewGuid().ToString();
var record = new PostDataModel(id, "name", PostType.TravelAgent, new PostConfiguration() { Rate = 10 });
var record = new PostDataModel(id, "name", PostType.SuperManager, new PostConfiguration() { Rate = 10 });
_postStorageContract.Setup(x => x.GetElementById(id)).Returns(record);
//Act
var element = _postBusinessLogicContract.GetPostByData(id);
@@ -175,7 +175,7 @@ internal class PostBusinessLogicContractTests
{
//Arrange
var postName = "name";
var record = new PostDataModel(Guid.NewGuid().ToString(), postName, PostType.TravelAgent, new PostConfiguration() { Rate = 10 });
var record = new PostDataModel(Guid.NewGuid().ToString(), postName, PostType.SuperManager, new PostConfiguration() { Rate = 10 });
_postStorageContract.Setup(x => x.GetElementByName(postName)).Returns(record);
//Act
var element = _postBusinessLogicContract.GetPostByData(postName);
@@ -231,7 +231,7 @@ internal class PostBusinessLogicContractTests
{
//Arrange
var flag = false;
var record = new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.TravelAgent, new PostConfiguration() { Rate = 10 });
var record = new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.SuperManager, new PostConfiguration() { Rate = 10 });
_postStorageContract.Setup(x => x.AddElement(It.IsAny<PostDataModel>()))
.Callback((PostDataModel x) =>
{
@@ -250,7 +250,7 @@ internal class PostBusinessLogicContractTests
//Arrange
_postStorageContract.Setup(x => x.AddElement(It.IsAny<PostDataModel>())).Throws(new ElementExistsException("Data", "Data"));
//Act&Assert
Assert.That(() => _postBusinessLogicContract.InsertPost(new(Guid.NewGuid().ToString(), "name", PostType.TravelAgent, new PostConfiguration() { Rate = 10 })), Throws.TypeOf<ElementExistsException>());
Assert.That(() => _postBusinessLogicContract.InsertPost(new(Guid.NewGuid().ToString(), "name", PostType.SuperManager, new PostConfiguration() { Rate = 10 })), Throws.TypeOf<ElementExistsException>());
_postStorageContract.Verify(x => x.AddElement(It.IsAny<PostDataModel>()), Times.Once);
}
@@ -266,7 +266,7 @@ internal class PostBusinessLogicContractTests
public void InsertPost_InvalidRecord_ThrowException_Test()
{
//Act&Assert
Assert.That(() => _postBusinessLogicContract.InsertPost(new PostDataModel("id", "name", PostType.TravelAgent, new PostConfiguration() { Rate = 10 })), Throws.TypeOf<ValidationException>());
Assert.That(() => _postBusinessLogicContract.InsertPost(new PostDataModel("id", "name", PostType.SuperManager, new PostConfiguration() { Rate = 10 })), Throws.TypeOf<ValidationException>());
_postStorageContract.Verify(x => x.AddElement(It.IsAny<PostDataModel>()), Times.Never);
}
@@ -276,7 +276,7 @@ internal class PostBusinessLogicContractTests
//Arrange
_postStorageContract.Setup(x => x.AddElement(It.IsAny<PostDataModel>())).Throws(new StorageException(new InvalidOperationException()));
//Act&Assert
Assert.That(() => _postBusinessLogicContract.InsertPost(new(Guid.NewGuid().ToString(), "name", PostType.TravelAgent, new PostConfiguration() { Rate = 10 })), Throws.TypeOf<StorageException>());
Assert.That(() => _postBusinessLogicContract.InsertPost(new(Guid.NewGuid().ToString(), "name", PostType.SuperManager, new PostConfiguration() { Rate = 10 })), Throws.TypeOf<StorageException>());
_postStorageContract.Verify(x => x.AddElement(It.IsAny<PostDataModel>()), Times.Once);
}
@@ -285,7 +285,7 @@ internal class PostBusinessLogicContractTests
{
//Arrange
var flag = false;
var record = new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.TravelAgent, new PostConfiguration() { Rate = 10 });
var record = new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.SuperManager, new PostConfiguration() { Rate = 10 });
_postStorageContract.Setup(x => x.UpdElement(It.IsAny<PostDataModel>()))
.Callback((PostDataModel x) =>
{
@@ -304,7 +304,7 @@ internal class PostBusinessLogicContractTests
//Arrange
_postStorageContract.Setup(x => x.UpdElement(It.IsAny<PostDataModel>())).Throws(new ElementNotFoundException(""));
//Act&Assert
Assert.That(() => _postBusinessLogicContract.UpdatePost(new(Guid.NewGuid().ToString(), "name", PostType.TravelAgent, new PostConfiguration() { Rate = 10 })), Throws.TypeOf<ElementNotFoundException>());
Assert.That(() => _postBusinessLogicContract.UpdatePost(new(Guid.NewGuid().ToString(), "name", PostType.SuperManager, new PostConfiguration() { Rate = 10 })), Throws.TypeOf<ElementNotFoundException>());
_postStorageContract.Verify(x => x.UpdElement(It.IsAny<PostDataModel>()), Times.Once);
}
@@ -314,7 +314,7 @@ internal class PostBusinessLogicContractTests
//Arrange
_postStorageContract.Setup(x => x.UpdElement(It.IsAny<PostDataModel>())).Throws(new ElementExistsException("Data", "Data"));
//Act&Assert
Assert.That(() => _postBusinessLogicContract.UpdatePost(new(Guid.NewGuid().ToString(), "anme", PostType.TravelAgent, new PostConfiguration() { Rate = 10 })), Throws.TypeOf<ElementExistsException>());
Assert.That(() => _postBusinessLogicContract.UpdatePost(new(Guid.NewGuid().ToString(), "anme", PostType.SuperManager, new PostConfiguration() { Rate = 10 })), Throws.TypeOf<ElementExistsException>());
_postStorageContract.Verify(x => x.UpdElement(It.IsAny<PostDataModel>()), Times.Once);
}
@@ -330,7 +330,7 @@ internal class PostBusinessLogicContractTests
public void UpdatePost_InvalidRecord_ThrowException_Test()
{
//Act&Assert
Assert.That(() => _postBusinessLogicContract.UpdatePost(new PostDataModel("id", "name", PostType.TravelAgent, new PostConfiguration() { Rate = 10 })), Throws.TypeOf<ValidationException>());
Assert.That(() => _postBusinessLogicContract.UpdatePost(new PostDataModel("id", "name", PostType.SuperManager, new PostConfiguration() { Rate = 10 })), Throws.TypeOf<ValidationException>());
_postStorageContract.Verify(x => x.UpdElement(It.IsAny<PostDataModel>()), Times.Never);
}
@@ -340,7 +340,7 @@ internal class PostBusinessLogicContractTests
//Arrange
_postStorageContract.Setup(x => x.UpdElement(It.IsAny<PostDataModel>())).Throws(new StorageException(new InvalidOperationException()));
//Act&Assert
Assert.That(() => _postBusinessLogicContract.UpdatePost(new(Guid.NewGuid().ToString(), "name", PostType.TravelAgent, new PostConfiguration() { Rate = 10 })), Throws.TypeOf<StorageException>());
Assert.That(() => _postBusinessLogicContract.UpdatePost(new(Guid.NewGuid().ToString(), "name", PostType.SuperManager, new PostConfiguration() { Rate = 10 })), Throws.TypeOf<StorageException>());
_postStorageContract.Verify(x => x.UpdElement(It.IsAny<PostDataModel>()), Times.Once);
}

View File

@@ -199,7 +199,7 @@ internal class SalaryBusinessLogicContractTests
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
.Returns([new SaleDataModel(Guid.NewGuid().ToString(), employeeId, null, DiscountType.None, false, [new SaleProductDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5, 1.2)])]);
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.TravelAgent, new PostConfiguration() { Rate = rate }));
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.SuperManager, new PostConfiguration() { Rate = rate }));
_employeeStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
.Returns([new EmployeeDataModel(employeeId, "Test", "abc@gmail.com", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false)]);
var sum = 0.0;
@@ -233,7 +233,7 @@ internal class SalaryBusinessLogicContractTests
new SaleDataModel(Guid.NewGuid().ToString(), employee3Id, null, DiscountType.None, false, []),
new SaleDataModel(Guid.NewGuid().ToString(), employee3Id, null, DiscountType.None, false, [])]);
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.TravelAgent, new PostConfiguration() { Rate = 100 }));
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.SuperManager, new PostConfiguration() { Rate = 100 }));
_employeeStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
.Returns(list);
//Act
@@ -251,7 +251,7 @@ internal class SalaryBusinessLogicContractTests
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
.Returns([]);
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.TravelAgent, new PostConfiguration() { Rate = rate }));
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.SuperManager, new PostConfiguration() { Rate = rate }));
_employeeStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
.Returns([new EmployeeDataModel(employeeId, "Test", "abc@gmail.com", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false)]);
var sum = 0.0;
@@ -272,7 +272,7 @@ internal class SalaryBusinessLogicContractTests
//Arrange
var employeeId = Guid.NewGuid().ToString();
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.TravelAgent, new PostConfiguration() { Rate = 100 }));
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.SuperManager, new PostConfiguration() { Rate = 100 }));
_employeeStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
.Returns([new EmployeeDataModel(employeeId, "Test", "abc@gmail.com", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false)]);
//Act&Assert
@@ -300,7 +300,7 @@ internal class SalaryBusinessLogicContractTests
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
.Returns([new SaleDataModel(Guid.NewGuid().ToString(), employeeId, null, DiscountType.None, false, [])]);
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.TravelAgent, new PostConfiguration() { Rate = 100 }));
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.SuperManager, new PostConfiguration() { Rate = 100 }));
//Act&Assert
Assert.That(() => _salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow), Throws.TypeOf<NullListException>());
}
@@ -313,7 +313,7 @@ internal class SalaryBusinessLogicContractTests
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
.Throws(new StorageException(new InvalidOperationException()));
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.TravelAgent, new PostConfiguration() { Rate = 100 }));
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.SuperManager, new PostConfiguration() { Rate = 100 }));
_employeeStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
.Returns([new EmployeeDataModel(employeeId, "Test", "abc@gmail.com", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false)]);
//Act&Assert
@@ -343,14 +343,14 @@ internal class SalaryBusinessLogicContractTests
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
.Returns([new SaleDataModel(Guid.NewGuid().ToString(), employeeId, null, DiscountType.None, false, [])]);
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.TravelAgent, new PostConfiguration() { Rate = 100 }));
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.SuperManager, new PostConfiguration() { Rate = 100 }));
_employeeStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
.Throws(new StorageException(new InvalidOperationException()));
//Act&Assert
Assert.That(() => _salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow), Throws.TypeOf<StorageException>());
}
[Test]
public void CalculateSalaryByMountht_WithTravelAgentPostConfiguration_CalculateSalary_Test()
public void CalculateSalaryByMountht_WithSuperManagerPostConfiguration_CalculateSalary_Test()
{
//Arrange
var employeeId = Guid.NewGuid().ToString();
@@ -366,7 +366,7 @@ internal class SalaryBusinessLogicContractTests
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
.Returns(sales);
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.TravelAgent, new ManagerPostConfiguration() { Rate = rate, SalePercent = percent, BonusForExtraSales = bonus }));
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.SuperManager, new ManagerPostConfiguration() { Rate = rate, SalePercent = percent, BonusForExtraSales = bonus }));
_employeeStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
.Returns([new EmployeeDataModel(employeeId, "Test", "abc@gmail.com", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false)]);
var sum = 0.0;
@@ -393,7 +393,7 @@ internal class SalaryBusinessLogicContractTests
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
.Returns([new SaleDataModel(Guid.NewGuid().ToString(), employeeId, null, DiscountType.None, false, [new SaleProductDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5, 1.2)])]);
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.TravelAgent, new BakerPostConfiguration() { Rate = rate, PersonalCountTrendPremium = bonus }));
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.SuperManager, new BakerPostConfiguration() { Rate = rate, PersonalCountTrendPremium = bonus }));
_employeeStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
.Returns([new EmployeeDataModel(employeeId, "Test", "abc@gmail.com", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false)]);
_employeeStorageContract.Setup(x => x.GetEmployeeTrend(It.IsAny<DateTime>(), It.IsAny<DateTime>()))

View File

@@ -10,25 +10,25 @@ internal class PostDataModelTests
[Test]
public void IdIsNullOrEmptyTest()
{
var post = CreateDataModel(null, "name", PostType.TravelAgent, new PostConfiguration() { Rate = 10 });
var post = CreateDataModel(null, "name", PostType.SuperManager, new PostConfiguration() { Rate = 10 });
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
post = CreateDataModel(string.Empty, "name", PostType.TravelAgent, new PostConfiguration() { Rate = 10 });
post = CreateDataModel(string.Empty, "name", PostType.SuperManager, new PostConfiguration() { Rate = 10 });
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void IdIsNotGuidTest()
{
var post = CreateDataModel("id", "name", PostType.TravelAgent, new PostConfiguration() { Rate = 10 });
var post = CreateDataModel("id", "name", PostType.SuperManager, new PostConfiguration() { Rate = 10 });
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void PostNameIsEmptyTest()
{
var manufacturer = CreateDataModel(Guid.NewGuid().ToString(), null, PostType.TravelAgent, new PostConfiguration() { Rate = 10 });
var manufacturer = CreateDataModel(Guid.NewGuid().ToString(), null, PostType.SuperManager, new PostConfiguration() { Rate = 10 });
Assert.That(() => manufacturer.Validate(), Throws.TypeOf<ValidationException>());
manufacturer = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, PostType.TravelAgent, new PostConfiguration() { Rate = 10 });
manufacturer = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, PostType.SuperManager, new PostConfiguration() { Rate = 10 });
Assert.That(() => manufacturer.Validate(), Throws.TypeOf<ValidationException>());
}
@@ -42,16 +42,16 @@ internal class PostDataModelTests
[Test]
public void ConfigurationModelIsNullTest()
{
var post = CreateDataModel(Guid.NewGuid().ToString(), "name", PostType.TravelAgent, null);
var post = CreateDataModel(Guid.NewGuid().ToString(), "name", PostType.SuperManager, null);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void RateIsLessOrZeroTest()
{
var post = CreateDataModel(Guid.NewGuid().ToString(), "name", PostType.TravelAgent, new PostConfiguration() { Rate = 0 });
var post = CreateDataModel(Guid.NewGuid().ToString(), "name", PostType.SuperManager, new PostConfiguration() { Rate = 0 });
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
post = CreateDataModel(Guid.NewGuid().ToString(), "name", PostType.TravelAgent, new PostConfiguration() { Rate = -10 });
post = CreateDataModel(Guid.NewGuid().ToString(), "name", PostType.SuperManager, new PostConfiguration() { Rate = -10 });
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
}

View File

@@ -21,7 +21,7 @@ internal static class CandyHouseDbContextExtensions
return client;
}
public static Post InsertPostToDatabaseAndReturn(this CandyHouseDbContext dbContext, string? id = null, string postName = "test", PostType postType = PostType.TravelAgent, PostConfiguration? config = null, bool isActual = true, DateTime? changeDate = null)
public static Post InsertPostToDatabaseAndReturn(this CandyHouseDbContext dbContext, string? id = null, string postName = "test", PostType postType = PostType.SuperManager, PostConfiguration? config = null, bool isActual = true, DateTime? changeDate = null)
{
var post = new Post() { Id = Guid.NewGuid().ToString(), PostId = id ?? Guid.NewGuid().ToString(), PostName = postName, PostType = postType, Configuration = config ?? new PostConfiguration() { Rate = 100 }, IsActual = isActual, ChangeDate = changeDate ?? DateTime.UtcNow };
dbContext.Posts.Add(post);

View File

@@ -161,7 +161,7 @@ internal class PostStorageContractTests : BaseStorageContractTest
}
[Test]
public void Try_AddElement_WithTravelAgentPostConfiguration_Test()
public void Try_AddElement_WithSuperManagerPostConfiguration_Test()
{
var salePercent = 10;
var post = CreateModel(Guid.NewGuid().ToString(), config: new ManagerPostConfiguration() { SalePercent = salePercent });
@@ -227,7 +227,7 @@ internal class PostStorageContractTests : BaseStorageContractTest
}
[Test]
public void Try_UpdElement_WithTravelAgentPostConfiguration_Test()
public void Try_UpdElement_WithSuperManagerPostConfiguration_Test()
{
var post = CandyHouseDbContext.InsertPostToDatabaseAndReturn();
var salePercent = 10;
@@ -315,7 +315,7 @@ internal class PostStorageContractTests : BaseStorageContractTest
});
}
private static PostDataModel CreateModel(string postId, string postName = "test", PostType postType = PostType.TravelAgent, PostConfiguration? config = null)
private static PostDataModel CreateModel(string postId, string postName = "test", PostType postType = PostType.SuperManager, PostConfiguration? config = null)
=> new(postId, postName, postType, config ?? new PostConfiguration() { Rate = 100 });
private static void AssertElement(Post? actual, PostDataModel expected)

View File

@@ -90,7 +90,7 @@ internal class PostControllerTests : BaseWebApiControllerTest
{
//Arrange
var postSimple = CandyHouseDbContext.InsertPostToDatabaseAndReturn(postName: "name 1");
var postTravelAgent = CandyHouseDbContext.InsertPostToDatabaseAndReturn(postName: "name 2", config: new ManagerPostConfiguration() { SalePercent = 500 });
var postSuperManager = CandyHouseDbContext.InsertPostToDatabaseAndReturn(postName: "name 2", config: new ManagerPostConfiguration() { SalePercent = 500 });
var postLoader = CandyHouseDbContext.InsertPostToDatabaseAndReturn(postName: "name 3", config: new BakerPostConfiguration() { PersonalCountTrendPremium = 20 });
//Act
var response = await HttpClient.GetAsync("/api/posts");
@@ -99,7 +99,7 @@ internal class PostControllerTests : BaseWebApiControllerTest
var data = await GetModelFromResponseAsync<List<PostViewModel>>(response);
Assert.That(data, Is.Not.Null);
AssertElement(data.First(x => x.Id == postSimple.PostId), postSimple);
AssertElement(data.First(x => x.Id == postTravelAgent.PostId), postTravelAgent);
AssertElement(data.First(x => x.Id == postSuperManager.PostId), postSuperManager);
AssertElement(data.First(x => x.Id == postLoader.PostId), postLoader);
}
@@ -221,10 +221,10 @@ internal class PostControllerTests : BaseWebApiControllerTest
public async Task Post_WhenDataIsIncorrect_ShouldBadRequest_Test()
{
//Arrange
var postModelWithIdIncorrect = new PostBindingModel { Id = "Id", PostName = "name", PostType = PostType.TravelAgent.ToString(), ConfigurationJson = JsonSerializer.Serialize(new PostConfiguration() { Rate = 10 }) };
var postModelWithNameIncorrect = new PostBindingModel { Id = Guid.NewGuid().ToString(), PostName = string.Empty, PostType = PostType.TravelAgent.ToString(), ConfigurationJson = JsonSerializer.Serialize(new PostConfiguration() { Rate = 10 }) };
var postModelWithIdIncorrect = new PostBindingModel { Id = "Id", PostName = "name", PostType = PostType.SuperManager.ToString(), ConfigurationJson = JsonSerializer.Serialize(new PostConfiguration() { Rate = 10 }) };
var postModelWithNameIncorrect = new PostBindingModel { Id = Guid.NewGuid().ToString(), PostName = string.Empty, PostType = PostType.SuperManager.ToString(), ConfigurationJson = JsonSerializer.Serialize(new PostConfiguration() { Rate = 10 }) };
var postModelWithPostTypeIncorrect = new PostBindingModel { Id = Guid.NewGuid().ToString(), PostName = string.Empty, PostType = string.Empty, ConfigurationJson = JsonSerializer.Serialize(new PostConfiguration() { Rate = 10 }) };
var postModelWithSalaryIncorrect = new PostBindingModel { Id = Guid.NewGuid().ToString(), PostName = string.Empty, PostType = PostType.TravelAgent.ToString(), ConfigurationJson = null };
var postModelWithSalaryIncorrect = new PostBindingModel { Id = Guid.NewGuid().ToString(), PostName = string.Empty, PostType = PostType.SuperManager.ToString(), ConfigurationJson = null };
//Act
var responseWithIdIncorrect = await HttpClient.PostAsync($"/api/posts", MakeContent(postModelWithIdIncorrect));
var responseWithNameIncorrect = await HttpClient.PostAsync($"/api/posts", MakeContent(postModelWithNameIncorrect));
@@ -259,7 +259,7 @@ internal class PostControllerTests : BaseWebApiControllerTest
}
[Test]
public async Task Post_WithTravelAgentPostConfiguration_ShouldSuccess_Test()
public async Task Post_WithSuperManagerPostConfiguration_ShouldSuccess_Test()
{
//Arrange
var salePercent = 10;
@@ -351,10 +351,10 @@ internal class PostControllerTests : BaseWebApiControllerTest
public async Task Put_WhenDataIsIncorrect_ShouldBadRequest_Test()
{
//Arrange
var postModelWithIdIncorrect = new PostBindingModel { Id = "Id", PostName = "name", PostType = PostType.TravelAgent.ToString(), ConfigurationJson = JsonSerializer.Serialize(new PostConfiguration() { Rate = 10 }) };
var postModelWithNameIncorrect = new PostBindingModel { Id = Guid.NewGuid().ToString(), PostName = string.Empty, PostType = PostType.TravelAgent.ToString(), ConfigurationJson = JsonSerializer.Serialize(new PostConfiguration() { Rate = 10 }) };
var postModelWithIdIncorrect = new PostBindingModel { Id = "Id", PostName = "name", PostType = PostType.SuperManager.ToString(), ConfigurationJson = JsonSerializer.Serialize(new PostConfiguration() { Rate = 10 }) };
var postModelWithNameIncorrect = new PostBindingModel { Id = Guid.NewGuid().ToString(), PostName = string.Empty, PostType = PostType.SuperManager.ToString(), ConfigurationJson = JsonSerializer.Serialize(new PostConfiguration() { Rate = 10 }) };
var postModelWithPostTypeIncorrect = new PostBindingModel { Id = Guid.NewGuid().ToString(), PostName = string.Empty, PostType = string.Empty, ConfigurationJson = JsonSerializer.Serialize(new PostConfiguration() { Rate = 10 }) };
var postModelWithSalaryIncorrect = new PostBindingModel { Id = Guid.NewGuid().ToString(), PostName = string.Empty, PostType = PostType.TravelAgent.ToString(), ConfigurationJson = null };
var postModelWithSalaryIncorrect = new PostBindingModel { Id = Guid.NewGuid().ToString(), PostName = string.Empty, PostType = PostType.SuperManager.ToString(), ConfigurationJson = null };
//Act
var responseWithIdIncorrect = await HttpClient.PutAsync($"/api/posts", MakeContent(postModelWithIdIncorrect));
var responseWithNameIncorrect = await HttpClient.PutAsync($"/api/posts", MakeContent(postModelWithNameIncorrect));
@@ -389,7 +389,7 @@ internal class PostControllerTests : BaseWebApiControllerTest
}
[Test]
public async Task Put_WithTravelAgentPostConfiguration_ShouldSuccess_Test()
public async Task Put_WithSuperManagerPostConfiguration_ShouldSuccess_Test()
{
//Arrange
var salePercent = 10;