public async Task TestGetProject_WithExistingProjectName_ShouldReturnProject() { // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var groupRepository = new EfDeletableEntityRepository <Product_Group>(context); var productRepository = new EfDeletableEntityRepository <Product>(context); var projectRepository = new EfDeletableEntityRepository <Project>(context); var groupService = new GroupService(groupRepository); var prodcutService = new ProductService(productRepository, groupService); var cloudinaryService = new FakeCloudinary(); var projectService = new ProjectService(projectRepository, cloudinaryService, prodcutService, groupService); var seeder = new DbContextTestsSeeder(); await seeder.SeedUsersAsync(context); await seeder.SeedGroupAsync(context); await seeder.SeedProjectAsync(context); // Act AutoMapperConfig.RegisterMappings(typeof(DetailsProjectViewModel).Assembly); var expected = context.Projects.SingleOrDefault(finishedModel => finishedModel.Product.Name == "Проект 1"); var actualResult = projectService.GetByName <DetailsProjectViewModel>("Проект 1"); // Assert AssertExtension.EqualsWithMessage(expected.Product.Name, actualResult.Name, string.Format(ErrorMessage, "GetProject with name, returns name")); AssertExtension.EqualsWithMessage(expected.TypeProject.ToString(), actualResult.TypeProject, string.Format(ErrorMessage, "GetFinishedModel with name, returns Type Of Project")); AssertExtension.EqualsWithMessage(expected.TypeLocation.ToString(), actualResult.TypeLocation, string.Format(ErrorMessage, "GetFinishedModel with name, returns Type Of Location")); AssertExtension.EqualsWithMessage(expected.Description, actualResult.Description, string.Format(ErrorMessage, "GetProject with name, returns description")); AssertExtension.EqualsWithMessage(expected.ImagePath, actualResult.ImagePath, string.Format(ErrorMessage, "GetProject with name, returns ImagePath")); }
public async Task TestGetAllSuggestProducts_WithoutGivenType_ShouldReturnAllSuggestProducts() { // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var groupRepository = new EfDeletableEntityRepository <Product_Group>(context); var productRepository = new EfDeletableEntityRepository <Product>(context); var suggestProductRepository = new EfDeletableEntityRepository <SuggestProduct>(context); var groupService = new GroupService(groupRepository); var suggestproductService = new SuggestProdcut(suggestProductRepository); var seeder = new DbContextTestsSeeder(); await seeder.SeedUsersAsync(context); await seeder.SeedGroupAsync(context); await seeder.SeedSuggestProductAsync(context); // Act AutoMapperConfig.RegisterMappings(typeof(IndexSuggestProductViewModel).Assembly); var result = suggestproductService.GetAllSuggestion <IndexSuggestProductViewModel>("abc1"); var expected = result.ToList().Count; var actual = context.SuggestProducts.Count(); // Assert Assert.True(expected == actual, string.Format(ErrorMessage, "GetAllSuggestion")); }
public async Task TestGetAllrojects_WithoutGivenType_ShouldReturnAllProject() { // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var groupRepository = new EfDeletableEntityRepository <Product_Group>(context); var productRepository = new EfDeletableEntityRepository <Product>(context); var projectRepository = new EfDeletableEntityRepository <Project>(context); var groupService = new GroupService(groupRepository); var prodcutService = new ProductService(productRepository, groupService); var cloudinaryService = new FakeCloudinary(); var projectService = new ProjectService(projectRepository, cloudinaryService, prodcutService, groupService); var seeder = new DbContextTestsSeeder(); await seeder.SeedUsersAsync(context); await seeder.SeedGroupAsync(context); await seeder.SeedProjectAsync(context); // Act AutoMapperConfig.RegisterMappings(typeof(AllProjectViewModel).Assembly); var result = projectService.GetAll <AllProjectViewModel>(); var count = result.ToList().Count; var actual = context.Projects.Count(); // Assert Assert.True(count == actual, string.Format(ErrorMessage, "GetAllProject")); }
public async Task AddSuggestProduct_ToNoneExistingFireplaceId_ShouldThrowException() { // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var groupRepository = new EfDeletableEntityRepository <Product_Group>(context); var productRepository = new EfDeletableEntityRepository <Product>(context); var fireplacesRepository = new EfDeletableEntityRepository <Fireplace_chamber>(context); var suggestItemsReposotory = new EfDeletableEntityRepository <SuggestProduct>(context); var groupService = new GroupService(groupRepository); var prodcutService = new ProductService(productRepository, groupService); var sugestItemsRepositoryService = new SuggestProdcut(suggestItemsReposotory); var cloudinaryService = new FakeCloudinary(); var fireplaceService = new FireplaceService(fireplacesRepository, groupService, prodcutService, cloudinaryService, sugestItemsRepositoryService); var seeder = new DbContextTestsSeeder(); await seeder.SeedUsersAsync(context); await seeder.SeedGroupAsync(context); await seeder.SeedProdcutAsync(context); await seeder.SeedFireplacesAsync(context); string[] selectedFireplace = new string[] { "Гк Оливия" }; // Act and Asseart AutoMapperConfig.RegisterMappings(typeof(DeleteFireplaceViewModel).Assembly); await Assert.ThrowsAsync <NullReferenceException>(() => fireplaceService.AddSuggestionToFireplaceAsync("Гк Мая", "Test id", selectedFireplace, null, null, null)); }
public async Task TestGetAllFireplaces_WithoutGivenType_ShouldReturnAllFireplaces() { // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var groupRepository = new EfDeletableEntityRepository <Product_Group>(context); var productRepository = new EfDeletableEntityRepository <Product>(context); var fireplacesRepository = new EfDeletableEntityRepository <Fireplace_chamber>(context); var suggestItemsReposotory = new EfDeletableEntityRepository <SuggestProduct>(context); var groupService = new GroupService(groupRepository); var prodcutService = new ProductService(productRepository, groupService); var sugestItemsRepositoryService = new SuggestProdcut(suggestItemsReposotory); var cloudinaryService = new FakeCloudinary(); var fireplaceService = new FireplaceService(fireplacesRepository, groupService, prodcutService, cloudinaryService, sugestItemsRepositoryService); var seeder = new DbContextTestsSeeder(); await seeder.SeedUsersAsync(context); await seeder.SeedGroupAsync(context); await seeder.SeedProdcutAsync(context); await seeder.SeedFireplacesAsync(context); // Act AutoMapperConfig.RegisterMappings(typeof(AllFireplaceViewModel).Assembly); var result = fireplaceService.GetAllFireplace <AllFireplaceViewModel>(); var count = result.ToList().Count; var actual = context.Fireplace_Chambers.Count(); // Assert Assert.True(count == actual, string.Format(ErrorMessage, "Get all user with data")); }
public async Task TestGetAllComments_WithoutGivenType_ShouldReturnAllComments() { // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var groupRepository = new EfDeletableEntityRepository <Product_Group>(context); var productRepository = new EfDeletableEntityRepository <Product>(context); var fireplaceRepository = new EfDeletableEntityRepository <Fireplace_chamber>(context); var suggestItemsReposotory = new EfDeletableEntityRepository <SuggestProduct>(context); var commentsRepository = new EfDeletableEntityRepository <Comment>(context); var groupService = new GroupService(groupRepository); var prodcutService = new ProductService(productRepository, groupService); var cloudinaryService = new FakeCloudinary(); var sugestItemsRepositoryService = new SuggestProdcut(suggestItemsReposotory); var emailSender = new FakeEmailSender(); var fireplaceService = new FireplaceService(fireplaceRepository, groupService, prodcutService, cloudinaryService, sugestItemsRepositoryService); var commentServices = new CommentService(commentsRepository, prodcutService, fireplaceService, emailSender); var seeder = new DbContextTestsSeeder(); await seeder.SeedUsersAsync(context); await seeder.SeedGroupAsync(context); await seeder.SeedCommentsAsync(context); // Act AutoMapperConfig.RegisterMappings(typeof(AllAccessorieViewModel).Assembly); var result = commentServices.GetAllComments <IndexCommentViewModel>("abc"); var expected = result.ToList().Count; var actual = context.Comments.Count(); // Assert Assert.True(expected == actual, string.Format(ErrorMessage, "GetAllCooments")); }
public async Task TestGetCountOfPageByTypeOfChamber_WithCorrectDate_ShouldReturenCorrectCount() { // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var groupRepository = new EfDeletableEntityRepository <Product_Group>(context); var productRepository = new EfDeletableEntityRepository <Product>(context); var finishedModelsRepository = new EfDeletableEntityRepository <Finished_Model>(context); var groupService = new GroupService(groupRepository); var prodcutService = new ProductService(productRepository, groupService); var cloudinaryService = new FakeCloudinary(); var finishedModelsService = new FinishedModelService(finishedModelsRepository, prodcutService, groupService, cloudinaryService); var seeder = new DbContextTestsSeeder(); await seeder.SeedUsersAsync(context); await seeder.SeedGroupAsync(context); await seeder.SeedFinishedModelssAsync(context); // Act var result = finishedModelsService.GetCountByTypeOfProject(TypeProject.Classic.ToString()); // Assert Assert.True(result == 2, string.Format(ErrorMessage, string.Format(ErrorMessage, "GetCountByTypeOfProject"))); }
public async Task TestGetAccessorie_WithExistingAccessorieName_ShouldReturnAccessorie() { // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var groupRepository = new EfDeletableEntityRepository <Product_Group>(context); var productRepository = new EfDeletableEntityRepository <Product>(context); var accessorieRepository = new EfDeletableEntityRepository <Accessorie>(context); var groupService = new GroupService(groupRepository); var prodcutService = new ProductService(productRepository, groupService); var cloudinaryService = new FakeCloudinary(); var accessorieService = new AccessoriesService(accessorieRepository, prodcutService, groupService, cloudinaryService); var seeder = new DbContextTestsSeeder(); await seeder.SeedUsersAsync(context); await seeder.SeedGroupAsync(context); await seeder.SeedAccessorieAsync(context); // Act AutoMapperConfig.RegisterMappings(typeof(DetailsAccessorieViewModel).Assembly); var expected = context.Accessories.SingleOrDefault(accessorie => accessorie.Product.Name == "Аксесоар 1"); var actualResult = accessorieService.GetByName <DetailsAccessorieViewModel>("Аксесоар 1"); // Assert AssertExtension.EqualsWithMessage(expected.Product.Name, actualResult.Name, string.Format(ErrorMessage, "GetAccessorie with name, returns name")); AssertExtension.EqualsWithMessage(expected.Description, actualResult.Description, string.Format(ErrorMessage, "GetAccessorie with name, returns description")); AssertExtension.EqualsWithMessage(expected.ImagePath, actualResult.ImagePath, string.Format(ErrorMessage, "GetAccessorie with name, returns ImagePath")); }
public async Task AddAnswerToComment_WithCorrectData_ShouldSuccessfullyAdd() { // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var groupRepository = new EfDeletableEntityRepository <Product_Group>(context); var productRepository = new EfDeletableEntityRepository <Product>(context); var fireplaceRepository = new EfDeletableEntityRepository <Fireplace_chamber>(context); var suggestItemsReposotory = new EfDeletableEntityRepository <SuggestProduct>(context); var commentsRepository = new EfDeletableEntityRepository <Comment>(context); var groupService = new GroupService(groupRepository); var prodcutService = new ProductService(productRepository, groupService); var cloudinaryService = new FakeCloudinary(); var sugestItemsRepositoryService = new SuggestProdcut(suggestItemsReposotory); var emailSender = new FakeEmailSender(); var fireplaceService = new FireplaceService(fireplaceRepository, groupService, prodcutService, cloudinaryService, sugestItemsRepositoryService); var commentServices = new CommentService(commentsRepository, prodcutService, fireplaceService, emailSender); var seeder = new DbContextTestsSeeder(); await seeder.SeedUsersAsync(context); await seeder.SeedGroupAsync(context); await seeder.SeedCommentsAsync(context); // Act AutoMapperConfig.RegisterMappings(typeof(CreateCommentInputModel).Assembly); var result = commentServices.CreateAnswer("Тестов отговор", "comId1"); var expected = "Тестов отговор"; var actual = context.Comments.SingleOrDefault(c => c.Id == "comId1").Answer; // Assert AssertExtension.EqualsWithMessage(actual, expected, string.Format(ErrorMessage, "CreateAnswer")); }
public async Task TestGetAllFinishedModels_WithGivenType_ShouldReturnAllFireplacesFromThatType() { // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var groupRepository = new EfDeletableEntityRepository <Product_Group>(context); var productRepository = new EfDeletableEntityRepository <Product>(context); var finishedModelsRepository = new EfDeletableEntityRepository <Finished_Model>(context); var groupService = new GroupService(groupRepository); var prodcutService = new ProductService(productRepository, groupService); var cloudinaryService = new FakeCloudinary(); var finishedModelsService = new FinishedModelService(finishedModelsRepository, prodcutService, groupService, cloudinaryService); var seeder = new DbContextTestsSeeder(); await seeder.SeedUsersAsync(context); await seeder.SeedGroupAsync(context); await seeder.SeedFinishedModelssAsync(context); // Act AutoMapperConfig.RegisterMappings(typeof(AllFinishedModelViewModel).Assembly); var result = finishedModelsService.GetAllFinishedModelsAsync <AllFinishedModelViewModel>(TypeProject.Classic.ToString()); var count = result.ToList().Count; // Assert Assert.True(count == 2, string.Format(ErrorMessage, "GetAllFinishedModels")); }
public async Task AddFinishedModel_WithCorrectData_ShouldSuccessfullyAdd() { // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var groupRepository = new EfDeletableEntityRepository <Product_Group>(context); var productRepository = new EfDeletableEntityRepository <Product>(context); var finishedModelsRepository = new EfDeletableEntityRepository <Finished_Model>(context); var groupService = new GroupService(groupRepository); var prodcutService = new ProductService(productRepository, groupService); var cloudinaryService = new FakeCloudinary(); var finishedModelsService = new FinishedModelService(finishedModelsRepository, prodcutService, groupService, cloudinaryService); var seeder = new DbContextTestsSeeder(); await seeder.SeedUsersAsync(context); await seeder.SeedGroupAsync(context); var user = new ApplicationUser { Id = "abc", FirstName = "Nikolay", LastName = "Doychev", Email = "*****@*****.**", EmailConfirmed = true, }; var fileName = "Img"; IFormFile file = new FormFile( new MemoryStream(Encoding.UTF8.GetBytes("This is a dummy file")), 0, 0, fileName, "dummy.png"); var finishedModel = new AddFinishedModelInputModel { Id = "abc1", Description = "Some description test 1", ImagePath = file, TypeProject = TypeProject.Classic.ToString(), Name = "Model 1", }; // Act AutoMapperConfig.RegisterMappings(typeof(AddFinishedModelInputModel).Assembly); var result = await finishedModelsService.AddFinishedModelAsync(finishedModel, user.Id.ToString()); var actual = context.Finished_Models.FirstOrDefault(x => x.Product.Name == "Model 1"); var expectedName = "Model 1"; var expectedDescription = "Some description test 1"; var expectedTypeOfProject = TypeProject.Classic.ToString(); // Assert AssertExtension.EqualsWithMessage(expectedName, actual.Product.Name, string.Format(ErrorMessage, "AddFinishedModel returns correct Name")); AssertExtension.EqualsWithMessage(expectedDescription, actual.Description, string.Format(ErrorMessage, "AddFinishedModel returns correct Power")); AssertExtension.EqualsWithMessage(expectedTypeOfProject, actual.TypeProject.ToString(), string.Format(ErrorMessage, "AddFinishedModel returns correct TypeOfProject")); }
public async Task TestGetFireplace_WithNoneExistingireplaceName_ShouldReturnNull() { // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var groupRepository = new EfDeletableEntityRepository <Product_Group>(context); var productRepository = new EfDeletableEntityRepository <Product>(context); var fireplacesRepository = new EfDeletableEntityRepository <Fireplace_chamber>(context); var suggestItemsReposotory = new EfDeletableEntityRepository <SuggestProduct>(context); var groupService = new GroupService(groupRepository); var prodcutService = new ProductService(productRepository, groupService); var sugestItemsRepositoryService = new SuggestProdcut(suggestItemsReposotory); var cloudinaryService = new FakeCloudinary(); var fireplaceService = new FireplaceService(fireplacesRepository, groupService, prodcutService, cloudinaryService, sugestItemsRepositoryService); var seeder = new DbContextTestsSeeder(); await seeder.SeedUsersAsync(context); await seeder.SeedGroupAsync(context); await seeder.SeedProdcutAsync(context); await seeder.SeedFireplacesAsync(context); AutoMapperConfig.RegisterMappings(typeof(DetailsFireplaceViewModel).Assembly); // Act and Assert Assert.Throws <ArgumentNullException>(() => fireplaceService.GetByName <DetailsFireplaceViewModel>("Тестово име")); }
public async Task TestGetCountOfPage_WithCorrectDate_ShouldReturenCorrectCount() { // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var groupRepository = new EfDeletableEntityRepository <Product_Group>(context); var productRepository = new EfDeletableEntityRepository <Product>(context); var accessorieRepository = new EfDeletableEntityRepository <Accessorie>(context); var groupService = new GroupService(groupRepository); var prodcutService = new ProductService(productRepository, groupService); var cloudinaryService = new FakeCloudinary(); var accessorieService = new AccessoriesService(accessorieRepository, prodcutService, groupService, cloudinaryService); var seeder = new DbContextTestsSeeder(); await seeder.SeedUsersAsync(context); await seeder.SeedGroupAsync(context); await seeder.SeedAccessorieAsync(context); // Act var expected = accessorieService.GetCount(); var actual = context.Accessories.Count(); // Assert Assert.True(expected == actual, string.Format(ErrorMessage, string.Format(ErrorMessage, "GetCount"))); }
public async Task TestGetProjectById_WithNoneExistingProjectId_ShouldReturnNull() { // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var groupRepository = new EfDeletableEntityRepository <Product_Group>(context); var productRepository = new EfDeletableEntityRepository <Product>(context); var projectRepository = new EfDeletableEntityRepository <Project>(context); var groupService = new GroupService(groupRepository); var prodcutService = new ProductService(productRepository, groupService); var cloudinaryService = new FakeCloudinary(); var projectService = new ProjectService(projectRepository, cloudinaryService, prodcutService, groupService); var seeder = new DbContextTestsSeeder(); await seeder.SeedUsersAsync(context); await seeder.SeedGroupAsync(context); await seeder.SeedProjectAsync(context); AutoMapperConfig.RegisterMappings(typeof(DetailsProjectViewModel).Assembly); // Act and Assert Assert.Throws <ArgumentNullException>(() => projectService.GetById <DetailsProjectViewModel>("Тестово id")); }
public async Task TestGetCountOfPageByTypeOfProjectAndTypeOfLoaction_WithCorrectDate_ShouldReturenCorrectCount() { // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var groupRepository = new EfDeletableEntityRepository <Product_Group>(context); var productRepository = new EfDeletableEntityRepository <Product>(context); var projectRepository = new EfDeletableEntityRepository <Project>(context); var groupService = new GroupService(groupRepository); var prodcutService = new ProductService(productRepository, groupService); var cloudinaryService = new FakeCloudinary(); var projectService = new ProjectService(projectRepository, cloudinaryService, prodcutService, groupService); var seeder = new DbContextTestsSeeder(); await seeder.SeedUsersAsync(context); await seeder.SeedGroupAsync(context); await seeder.SeedProjectAsync(context); // Act var expected = projectService.GetCountByTypeOfChamber(TypeLocation.Corner.ToString(), TypeProject.Classic.ToString()); var actual = context.Projects.Count(); // Assert Assert.True(expected == actual, string.Format(ErrorMessage, string.Format(ErrorMessage, "GetCountByTypeOfProjectAndTypeOfLocation"))); }
public async Task DeleteFireplace_WithNonExistingFireplace_ShouldThrowException() { // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var groupRepository = new EfDeletableEntityRepository <Product_Group>(context); var productRepository = new EfDeletableEntityRepository <Product>(context); var fireplacesRepository = new EfDeletableEntityRepository <Fireplace_chamber>(context); var suggestItemsReposotory = new EfDeletableEntityRepository <SuggestProduct>(context); var groupService = new GroupService(groupRepository); var prodcutService = new ProductService(productRepository, groupService); var sugestItemsRepositoryService = new SuggestProdcut(suggestItemsReposotory); var cloudinaryService = new FakeCloudinary(); var fireplaceService = new FireplaceService(fireplacesRepository, groupService, prodcutService, cloudinaryService, sugestItemsRepositoryService); var user = new ApplicationUser { Id = "abc", FirstName = "Nikolay", LastName = "Doychev", Email = "*****@*****.**", EmailConfirmed = true, }; var fileName = "Img"; IFormFile file = new FormFile( new MemoryStream(Encoding.UTF8.GetBytes("This is a dummy file")), 0, 0, fileName, "dummy.png"); var fireplace = new DeleteFireplaceViewModel { Id = "Test Id", Power = "10w", Chimney = "200Ф", Description = "Some description test 1", ImagePath = "Some dummy data", Price = 1800.00M, Size = "60 / 40 / h50", TypeOfChamber = TypeOfChamber.Basic.ToString(), Name = "Гк Мая", }; var seeder = new DbContextTestsSeeder(); await seeder.SeedUsersAsync(context); await seeder.SeedGroupAsync(context); await seeder.SeedProdcutAsync(context); await seeder.SeedFireplacesAsync(context); // Act AutoMapperConfig.RegisterMappings(typeof(DeleteFireplaceViewModel).Assembly); await Assert.ThrowsAsync <NullReferenceException>(() => fireplaceService.DeleteAsync <DeleteFireplaceViewModel>(fireplace)); }
public async Task EditProject_WithCorrectData_ShouldSuccessfullyEdit() { // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var groupRepository = new EfDeletableEntityRepository <Product_Group>(context); var productRepository = new EfDeletableEntityRepository <Product>(context); var accessorieRepository = new EfDeletableEntityRepository <Accessorie>(context); var groupService = new GroupService(groupRepository); var prodcutService = new ProductService(productRepository, groupService); var cloudinaryService = new FakeCloudinary(); var accessorieService = new AccessoriesService(accessorieRepository, prodcutService, groupService, cloudinaryService); var user = new ApplicationUser { Id = "abc", FirstName = "Nikolay", LastName = "Doychev", Email = "*****@*****.**", EmailConfirmed = true, }; var fileName = "Img"; IFormFile file = new FormFile( new MemoryStream(Encoding.UTF8.GetBytes("This is a dummy file")), 0, 0, fileName, "dummy.png"); var accessorie = new EditAccessorieViewModel { Id = "abc1", Description = "Some description test 1", ImagePath = file, Name = "Аксесоар 1 сменено", }; var seeder = new DbContextTestsSeeder(); await seeder.SeedUsersAsync(context); await seeder.SeedGroupAsync(context); await seeder.SeedAccessorieAsync(context); // Act AutoMapperConfig.RegisterMappings(typeof(EditAccessorieViewModel).Assembly); var result = await accessorieService.EditAsync <EditAccessorieViewModel>(accessorie); var actual = context.Accessories.FirstOrDefault(x => x.Product.Name == "Аксесоар 1 сменено"); var expectedName = "Аксесоар 1 сменено"; var expectedDescription = "Some description test 1"; // Assert AssertExtension.EqualsWithMessage(expectedName, actual.Product.Name, string.Format(ErrorMessage, "EditAccessorie returns correct Name")); AssertExtension.EqualsWithMessage(expectedDescription, actual.Description, string.Format(ErrorMessage, "EditAccessorie returns correct Description")); }
public async Task AddComment_WithNoneExistingProduct_ShouldThrowException() { // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var groupRepository = new EfDeletableEntityRepository <Product_Group>(context); var productRepository = new EfDeletableEntityRepository <Product>(context); var fireplaceRepository = new EfDeletableEntityRepository <Fireplace_chamber>(context); var suggestItemsReposotory = new EfDeletableEntityRepository <SuggestProduct>(context); var commentsRepository = new EfDeletableEntityRepository <Comment>(context); var groupService = new GroupService(groupRepository); var prodcutService = new ProductService(productRepository, groupService); var cloudinaryService = new FakeCloudinary(); var sugestItemsRepositoryService = new SuggestProdcut(suggestItemsReposotory); var emailSender = new FakeEmailSender(); var fireplaceService = new FireplaceService(fireplaceRepository, groupService, prodcutService, cloudinaryService, sugestItemsRepositoryService); var commentServices = new CommentService(commentsRepository, prodcutService, fireplaceService, emailSender); var user = new ApplicationUser { Id = "abc", FirstName = "Nikolay", LastName = "Doychev", Email = "*****@*****.**", EmailConfirmed = true, }; var fileName = "Img"; IFormFile file = new FormFile( new MemoryStream(Encoding.UTF8.GetBytes("This is a dummy file")), 0, 0, fileName, "dummy.png"); var comment = new CreateCommentInputModel() { FullName = "Павлина Якимова", Email = "*****@*****.**", Content = "Тестов коментар", ProductId = "abc1", ProductName = "Тестово име", }; var seeder = new DbContextTestsSeeder(); await seeder.SeedUsersAsync(context); await seeder.SeedGroupAsync(context); await seeder.SeedProdcutAsync(context); await seeder.SeedFireplacesAsync(context); // Act AutoMapperConfig.RegisterMappings(typeof(CreateCommentInputModel).Assembly); await Assert.ThrowsAsync <ArgumentNullException>(() => commentServices.Create(comment)); }
public async Task DeleteProject_WithCorrectData_ShouldSuccessfullyDelete() { // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var groupRepository = new EfDeletableEntityRepository <Product_Group>(context); var productRepository = new EfDeletableEntityRepository <Product>(context); var projectRepository = new EfDeletableEntityRepository <Project>(context); var groupService = new GroupService(groupRepository); var prodcutService = new ProductService(productRepository, groupService); var cloudinaryService = new FakeCloudinary(); var projectService = new ProjectService(projectRepository, cloudinaryService, prodcutService, groupService); var user = new ApplicationUser { Id = "abc", FirstName = "Nikolay", LastName = "Doychev", Email = "*****@*****.**", EmailConfirmed = true, }; var fileName = "Img"; IFormFile file = new FormFile( new MemoryStream(Encoding.UTF8.GetBytes("This is a dummy file")), 0, 0, fileName, "dummy.png"); var project = new DeleteProjectViewModel { Id = "abc1", Description = "Some description test 1", TypeProject = TypeProject.Classic.ToString(), TypeLocation = TypeLocation.Corner.ToString(), Name = "Проект 1", }; var seeder = new DbContextTestsSeeder(); await seeder.SeedUsersAsync(context); await seeder.SeedGroupAsync(context); await seeder.SeedProjectAsync(context); // Act AutoMapperConfig.RegisterMappings(typeof(DeleteProjectViewModel).Assembly); await projectService.DeleteAsync <DeleteProjectViewModel>(project); int actual = context.Projects.Count(); // Assert Assert.True(actual == 1, string.Format(ErrorMessage, "DeleteProject method")); }
public async Task DeleteProject_WithNonExistingProject_ShouldThrowException() { // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var groupRepository = new EfDeletableEntityRepository <Product_Group>(context); var productRepository = new EfDeletableEntityRepository <Product>(context); var projectRepository = new EfDeletableEntityRepository <Project>(context); var groupService = new GroupService(groupRepository); var prodcutService = new ProductService(productRepository, groupService); var cloudinaryService = new FakeCloudinary(); var projectService = new ProjectService(projectRepository, cloudinaryService, prodcutService, groupService); var user = new ApplicationUser { Id = "abc", FirstName = "Nikolay", LastName = "Doychev", Email = "*****@*****.**", EmailConfirmed = true, }; var fileName = "Img"; IFormFile file = new FormFile( new MemoryStream(Encoding.UTF8.GetBytes("This is a dummy file")), 0, 0, fileName, "dummy.png"); var project = new DeleteProjectViewModel { Id = "Test Id", Description = "Some description test 1", ImagePath = "Some dummy data", TypeProject = TypeProject.Classic.ToString(), TypeLocation = TypeLocation.Corner.ToString(), Name = "Проект 1", }; var seeder = new DbContextTestsSeeder(); await seeder.SeedUsersAsync(context); await seeder.SeedGroupAsync(context); await seeder.SeedProjectAsync(context); // Act AutoMapperConfig.RegisterMappings(typeof(DeleteProjectViewModel).Assembly); await Assert.ThrowsAsync <NullReferenceException>(() => projectService.DeleteAsync <DeleteProjectViewModel>(project)); }
public async Task AddFinishedModel_WithNullValue_ShouldThrowException() { // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var groupRepository = new EfDeletableEntityRepository <Product_Group>(context); var productRepository = new EfDeletableEntityRepository <Product>(context); var finishedModelsRepository = new EfDeletableEntityRepository <Finished_Model>(context); var groupService = new GroupService(groupRepository); var prodcutService = new ProductService(productRepository, groupService); var cloudinaryService = new FakeCloudinary(); var finishedModelsService = new FinishedModelService(finishedModelsRepository, prodcutService, groupService, cloudinaryService); var user = new ApplicationUser { Id = "abc", FirstName = "Nikolay", LastName = "Doychev", Email = "*****@*****.**", EmailConfirmed = true, }; var fileName = "Img"; IFormFile file = new FormFile( new MemoryStream(Encoding.UTF8.GetBytes("This is a dummy file")), 0, 0, fileName, "dummy.png"); var finishedModel = new AddFinishedModelInputModel { Id = "abc1", Description = "Some description test 1", TypeProject = TypeProject.Classic.ToString(), Name = "Model 1", }; var seeder = new DbContextTestsSeeder(); await seeder.SeedUsersAsync(context); await seeder.SeedGroupAsync(context); await seeder.SeedProdcutAsync(context); // Act AutoMapperConfig.RegisterMappings(typeof(AddFinishedModelInputModel).Assembly); await Assert.ThrowsAsync <ArgumentNullException>(() => finishedModelsService.AddFinishedModelAsync(finishedModel, user.Id.ToString())); }
public async Task EditAccessorie_WithNonExistingAccessorie_ShouldThrowException() { // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var groupRepository = new EfDeletableEntityRepository <Product_Group>(context); var productRepository = new EfDeletableEntityRepository <Product>(context); var accessorieRepository = new EfDeletableEntityRepository <Accessorie>(context); var groupService = new GroupService(groupRepository); var prodcutService = new ProductService(productRepository, groupService); var cloudinaryService = new FakeCloudinary(); var accessorieService = new AccessoriesService(accessorieRepository, prodcutService, groupService, cloudinaryService); var user = new ApplicationUser { Id = "abc", FirstName = "Nikolay", LastName = "Doychev", Email = "*****@*****.**", EmailConfirmed = true, }; var fileName = "Img"; IFormFile file = new FormFile( new MemoryStream(Encoding.UTF8.GetBytes("This is a dummy file")), 0, 0, fileName, "dummy.png"); var accessorie = new EditAccessorieViewModel { Id = "Test Id", Description = "Some description test 1", Name = "Аксесоар 1", ImagePath = file, }; var seeder = new DbContextTestsSeeder(); await seeder.SeedUsersAsync(context); await seeder.SeedGroupAsync(context); await seeder.SeedProjectAsync(context); // Act AutoMapperConfig.RegisterMappings(typeof(EditAccessorieViewModel).Assembly); await Assert.ThrowsAsync <NullReferenceException>(() => accessorieService.EditAsync <EditAccessorieViewModel>(accessorie)); }
public async Task FindProduct_WithNoneExistingId_ShouldThrowException() { // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var groupRepository = new EfDeletableEntityRepository <Product_Group>(context); var productRepository = new EfDeletableEntityRepository <Product>(context); var groupService = new GroupService(groupRepository); var productService = new ProductService(productRepository, groupService); var seeder = new DbContextTestsSeeder(); await seeder.SeedGroupAsync(context); await seeder.SeedProdcutAsync(context); // Act and Assert Assert.Throws <ArgumentNullException>(() => productService.GetById("Тестово id")); }
public async Task AddProductToDataBase_WithNoneExistingGroupName_ShouldThrowException() { // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var groupRepository = new EfDeletableEntityRepository <Product_Group>(context); var productRepository = new EfDeletableEntityRepository <Product>(context); var groupService = new GroupService(groupRepository); var productService = new ProductService(productRepository, groupService); var seeder = new DbContextTestsSeeder(); await seeder.SeedGroupAsync(context); await seeder.SeedProdcutAsync(context); // Act and Assert await Assert.ThrowsAsync <ArgumentException>(() => productService.AddProductAsync("Гк Зузуя", "Test group", "userId")); }
public async Task AddProductToDataBase_WithCorrectData_ShouldSuccessfullyAdd() { // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var groupRepository = new EfDeletableEntityRepository <Product_Group>(context); var productRepository = new EfDeletableEntityRepository <Product>(context); var groupService = new GroupService(groupRepository); var productService = new ProductService(productRepository, groupService); var seeder = new DbContextTestsSeeder(); await seeder.SeedGroupAsync(context); // Act await productService.AddProductAsync("product", GroupType.Fireplace.ToString(), "abc1"); var actual = context.Products.Count(); // Assert Assert.True(actual == 1, string.Format(ErrorMessage, "ProductAdd")); }
public async Task FindProductIdBy_WithNoneExistingName_ShouldreturnNull() { // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var groupRepository = new EfDeletableEntityRepository <Product_Group>(context); var productRepository = new EfDeletableEntityRepository <Product>(context); var groupService = new GroupService(groupRepository); var productService = new ProductService(productRepository, groupService); var seeder = new DbContextTestsSeeder(); await seeder.SeedGroupAsync(context); await seeder.SeedProdcutAsync(context); // Act var result = productService.GetIdByNameAndGroup("Test Name", GroupType.Fireplace.ToString()); // Assert AssertExtension.EqualsWithMessage(null, result, string.Format(ErrorMessage, "ProductGetIdByNameAndGroup return null")); }
public async Task TestGetFireplace_WithExistingFireplaceName_ShouldReturnFireplace() { // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var groupRepository = new EfDeletableEntityRepository <Product_Group>(context); var productRepository = new EfDeletableEntityRepository <Product>(context); var fireplacesRepository = new EfDeletableEntityRepository <Fireplace_chamber>(context); var suggestItemsReposotory = new EfDeletableEntityRepository <SuggestProduct>(context); var groupService = new GroupService(groupRepository); var prodcutService = new ProductService(productRepository, groupService); var sugestItemsRepositoryService = new SuggestProdcut(suggestItemsReposotory); var cloudinaryService = new FakeCloudinary(); var fireplaceService = new FireplaceService(fireplacesRepository, groupService, prodcutService, cloudinaryService, sugestItemsRepositoryService); var seeder = new DbContextTestsSeeder(); await seeder.SeedUsersAsync(context); await seeder.SeedGroupAsync(context); await seeder.SeedProdcutAsync(context); await seeder.SeedFireplacesAsync(context); // Act AutoMapperConfig.RegisterMappings(typeof(DetailsFireplaceViewModel).Assembly); var expected = context.Fireplace_Chambers.SingleOrDefault(fireplace => fireplace.Product.Name == "Гк Мая"); var actualResult = fireplaceService.GetByName <DetailsFireplaceViewModel>("Гк Мая"); // Assert AssertExtension.EqualsWithMessage(expected.Product.Name, actualResult.Name, string.Format(ErrorMessage, "GetFireplace with name, returns name")); AssertExtension.EqualsWithMessage(expected.Power, actualResult.Power, string.Format(ErrorMessage, "GetFireplace with name, returns power")); AssertExtension.EqualsWithMessage(expected.Chimney, actualResult.Chimney, string.Format(ErrorMessage, "GetFireplace with name, returns chimney")); Assert.Equal(expected.Price, actualResult.Price); AssertExtension.EqualsWithMessage(expected.Description, actualResult.Description, string.Format(ErrorMessage, "GetFireplace with name, returns description")); AssertExtension.EqualsWithMessage(expected.ImagePath, actualResult.ImagePath, string.Format(ErrorMessage, "GetFireplace with name, returns ImagePath")); }
public async Task AddSuggestProduct_WithCorrectData_ShouldSuccessfullyAddSuggestion() { // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var groupRepository = new EfDeletableEntityRepository <Product_Group>(context); var productRepository = new EfDeletableEntityRepository <Product>(context); var fireplacesRepository = new EfDeletableEntityRepository <Fireplace_chamber>(context); var suggestItemsReposotory = new EfDeletableEntityRepository <SuggestProduct>(context); var groupService = new GroupService(groupRepository); var prodcutService = new ProductService(productRepository, groupService); var sugestItemsRepositoryService = new SuggestProdcut(suggestItemsReposotory); var cloudinaryService = new FakeCloudinary(); var fireplaceService = new FireplaceService(fireplacesRepository, groupService, prodcutService, cloudinaryService, sugestItemsRepositoryService); var seeder = new DbContextTestsSeeder(); await seeder.SeedUsersAsync(context); await seeder.SeedGroupAsync(context); await seeder.SeedProdcutAsync(context); await seeder.SeedFireplacesAsync(context); string[] selectedFireplace = new string[] { "Гк Оливия" }; // Act AutoMapperConfig.RegisterMappings(typeof(FireplaceInputModel).Assembly); await fireplaceService.AddSuggestionToFireplaceAsync("Гк Мая", "abc1", selectedFireplace, null, null, null); var count = context.SuggestProducts.Count(); // Assert Assert.True(count == 1, string.Format(ErrorMessage, "Add suggestion method")); }
public async Task FindProduct_WithExistingId_ShouldSuccessfullyFind() { // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var groupRepository = new EfDeletableEntityRepository <Product_Group>(context); var productRepository = new EfDeletableEntityRepository <Product>(context); var groupService = new GroupService(groupRepository); var productService = new ProductService(productRepository, groupService); var seeder = new DbContextTestsSeeder(); await seeder.SeedGroupAsync(context); await seeder.SeedProdcutAsync(context); // Act var result = productService.GetById("abc").Name; var actual = context.Products.SingleOrDefault(p => p.Id == "abc").Name; // Assert AssertExtension.EqualsWithMessage(actual, result, string.Format(ErrorMessage, "ProductGetIdByNameAndGroup")); }
public async Task EditFireplace_WithCorrectData_ShouldSuccessfullyEdit() { // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var groupRepository = new EfDeletableEntityRepository <Product_Group>(context); var productRepository = new EfDeletableEntityRepository <Product>(context); var fireplacesRepository = new EfDeletableEntityRepository <Fireplace_chamber>(context); var suggestItemsReposotory = new EfDeletableEntityRepository <SuggestProduct>(context); var groupService = new GroupService(groupRepository); var prodcutService = new ProductService(productRepository, groupService); var sugestItemsRepositoryService = new SuggestProdcut(suggestItemsReposotory); var cloudinaryService = new FakeCloudinary(); var fireplaceService = new FireplaceService(fireplacesRepository, groupService, prodcutService, cloudinaryService, sugestItemsRepositoryService); var user = new ApplicationUser { Id = "abc", FirstName = "Nikolay", LastName = "Doychev", Email = "*****@*****.**", EmailConfirmed = true, }; var fileName = "Img"; IFormFile file = new FormFile( new MemoryStream(Encoding.UTF8.GetBytes("This is a dummy file")), 0, 0, fileName, "dummy.png"); var fireplace = new EditFireplaceViewModel { Id = "abc1", Power = "10w", Chimney = "200Ф", Description = "Some description test 1", ImagePath = file, Price = 1800.00M, Size = "60 / 40 / h50", TypeOfChamber = TypeOfChamber.Basic.ToString(), Name = "Гк Мая сменено", }; var seeder = new DbContextTestsSeeder(); await seeder.SeedUsersAsync(context); await seeder.SeedGroupAsync(context); await seeder.SeedProdcutAsync(context); await seeder.SeedFireplacesAsync(context); // Act AutoMapperConfig.RegisterMappings(typeof(EditFireplaceViewModel).Assembly); var result = await fireplaceService.EditAsync <EditFireplaceViewModel>(fireplace); var actual = context.Fireplace_Chambers.FirstOrDefault(x => x.Product.Name == "Гк Мая сменено"); var expectedName = "Гк Мая сменено"; var expectedPower = "10w"; var expectedChimney = "200Ф"; var expectedPrice = 1800.00M; var expectedSize = "60 / 40 / h50"; var expectedTypeOfChamber = TypeOfChamber.Basic.ToString(); // Assert AssertExtension.EqualsWithMessage(expectedName, actual.Product.Name, string.Format(ErrorMessage, "AddFireplace returns correct Name")); AssertExtension.EqualsWithMessage(expectedPower, actual.Power, string.Format(ErrorMessage, "AddFireplace returns correct Power")); AssertExtension.EqualsWithMessage(expectedChimney, actual.Chimney, string.Format(ErrorMessage, "AddFireplace returns correct Chimney")); Assert.Equal(expectedPrice, actual.Price); AssertExtension.EqualsWithMessage(expectedSize, actual.Size, string.Format(ErrorMessage, "AddFireplace returns correct Size")); AssertExtension.EqualsWithMessage(expectedTypeOfChamber, actual.TypeOfChamber.ToString(), string.Format(ErrorMessage, "AddFireplace returns correct TypeOfChamber")); }