private async Task <Guid> PostProjectAsync(AddProjectInputModel inputModel) { var postProjectResponse = await _httpClient.PostAsJsonAsync(_projectEndpoint, inputModel); var postProjectResponseContent = await postProjectResponse.Content.ReadAsStringAsync(); var projectId = JsonConvert.DeserializeObject <Guid>(postProjectResponseContent); return(projectId); }
public async Task AddProject_WithNullValue_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 AddProjectInputModel { 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(AddProjectInputModel).Assembly); await Assert.ThrowsAsync <ArgumentNullException>(() => projectService.AddProjectAsync(project, user.Id.ToString())); }
public async Task <IActionResult> Add(AddProjectInputModel inputModel) { if (!this.ModelState.IsValid) { return(this.View(inputModel)); } var user = await this.userManager.GetUserAsync(this.User); await this.projectService.AddProjectAsync(inputModel, user.Id.ToString()); var typeOfChamber = Enum.Parse <TypeProject>(inputModel.TypeProject); var typeLocation = Enum.Parse <TypeLocation>(inputModel.TypeLocation); this.TempData["SuccessfullyCreateProject"] = $"Успешно създаден проект {inputModel.Name}"; return(this.RedirectToAction("All", "Project", new { typeLocation = typeLocation, type = typeOfChamber, area = string.Empty })); }
public async Task <string> AddProjectAsync(AddProjectInputModel model, string userId) { var typeOfProject = Enum.Parse <TypeProject>(model.TypeProject); var typeOfLocation = Enum.Parse <TypeLocation>(model.TypeLocation); if (model.Name == null || model.ImagePath == null) { throw new ArgumentNullException(NullProjectPropertiesErrorMessage); } await this.productService.AddProductAsync(model.Name, model.Group, userId); var productId = this.productService.GetIdByNameAndGroup(model.Name, model.Group); var groupId = this.groupService.FindByGroupName(model.Group).Id; var photoUrl = await this.cloudinaryService.UploadPhotoAsync( model.ImagePath, $"{model.Group}_{model.Name}_{model.Id}", GlobalConstants.CloudFolderForProjectPhotos); var projectModel = new Project { Id = Guid.NewGuid().ToString(), CreatedOn = DateTime.UtcNow, Description = model.Description, IsDeleted = false, ImagePath = photoUrl, GroupId = groupId, ProductId = productId, TypeProject = typeOfProject, TypeLocation = typeOfLocation, }; await this.projectRepository.AddAsync(projectModel); await this.projectRepository.SaveChangesAsync(); return(projectModel.Id); }
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 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); 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 AddProjectInputModel { Id = "abc1", Description = "Some description test 1", ImagePath = file, TypeProject = TypeProject.Classic.ToString(), TypeLocation = TypeLocation.Corner.ToString(), Name = "Проект 1", }; // Act AutoMapperConfig.RegisterMappings(typeof(AddProjectInputModel).Assembly); var result = await projectService.AddProjectAsync(project, user.Id.ToString()); 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 expectedTypeOfLocation = TypeLocation.Corner.ToString(); // Assert AssertExtension.EqualsWithMessage(expectedName, actual.Product.Name, string.Format(ErrorMessage, "AddProject returns correct Name")); AssertExtension.EqualsWithMessage(expectedDescription, actual.Description, string.Format(ErrorMessage, "AddProject returns correct Description")); AssertExtension.EqualsWithMessage(expectedTypeOfProject, actual.TypeProject.ToString(), string.Format(ErrorMessage, "AddProject returns correct TypeOfProject")); AssertExtension.EqualsWithMessage(expectedTypeOfLocation, actual.TypeLocation.ToString(), string.Format(ErrorMessage, "AddProject returns correct TypeOfLoaction")); }
public IActionResult Add() { var createProjectInputModel = new AddProjectInputModel(); return(this.View(createProjectInputModel)); }