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 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 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 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 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 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 EditProject_WithCorrectData_ShouldSuccessfullyEdit() { // 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 EditProjectViewModel { Id = "abc1", Description = "Some description test 1", ImagePath = file, 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(EditProjectViewModel).Assembly); var result = await projectService.EditAsync <EditProjectViewModel>(project); var actual = context.Projects.FirstOrDefault(x => x.Product.Name == "Проект 1 сменено"); var expectedName = "Проект 1 сменено"; var expectedDescription = "Some description test 1"; var expectedTypeOfProject = TypeProject.Classic.ToString(); var expectedTypeLocation = TypeLocation.Corner.ToString(); // Assert AssertExtension.EqualsWithMessage(expectedName, actual.Product.Name, string.Format(ErrorMessage, "EditProject returns correct Name")); AssertExtension.EqualsWithMessage(expectedDescription, actual.Description, string.Format(ErrorMessage, "EditProject returns correct Description")); AssertExtension.EqualsWithMessage(expectedTypeOfProject, actual.TypeProject.ToString(), string.Format(ErrorMessage, "EditProject returns correct TypeOfProject")); AssertExtension.EqualsWithMessage(expectedTypeLocation, actual.TypeLocation.ToString(), string.Format(ErrorMessage, "EditProject returns correct TypeLocation")); }