public async Task EditAsync_SouldReturn_True_IfInputDataIsCorrect() { var db = this.GetDatabase(); var mapper = this.GetMapper(); var firstProp = new Property { Id = 1, IsActual = true, Description = "A lot of" }; var secondProp = new Property { Id = 2, IsActual = true, Description = "None" }; await db.Properties.AddRangeAsync(firstProp, secondProp); await db.SaveChangesAsync(); var propertyService = new PropertiesService(mapper, db); //Act var result = await propertyService.EditAsync(1, "Not Active", false); var editedProperty = await db.Properties.FirstOrDefaultAsync(x => x.Id == 1); //Assert result .Should() .BeTrue(); editedProperty .Should() .BeOfType <Property>() .And .Match <Property>(p => p.IsActual == false && p.Description == "Not Active"); }
public async Task EditAsync_SouldReturn_False_IfPropertyDoNotExist() { var db = this.GetDatabase(); var mapper = this.GetMapper(); var firstProp = new Property { Id = 1, IsActual = true, Description = "A lot of" }; var secondProp = new Property { Id = 2, IsActual = true, Description = "None" }; await db.Properties.AddRangeAsync(firstProp, secondProp); await db.SaveChangesAsync(); var propertyService = new PropertiesService(mapper, db); //Act var result = await propertyService.EditAsync(3, "Not Active", false); var editedProperty = await db.Properties.FirstOrDefaultAsync(x => x.Id == 3); //Assert result .Should() .BeFalse(); editedProperty .Should() .BeNull(); }
public async Task EditShouldSucceed() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: "EditPropertiesTestDb").Options; using var dbContext = new ApplicationDbContext(options); var propertyId = 5; var propertyName = $"Property with ID {propertyId}"; dbContext.Properties.Add(new Property() { Id = propertyId, Name = propertyName, }); await dbContext.SaveChangesAsync(); using var propertyRepository = new EfDeletableEntityRepository <Property>(dbContext); var propertiesService = new PropertiesService(propertyRepository); var editedName = $"Edited Property with ID {propertyId}"; var model = new EditPropertiesViewModel() { Name = editedName, }; var property = propertiesService.EditAsync(propertyId, model); var editedPropety = dbContext.Properties.FirstOrDefault(p => p.Id == propertyId); Assert.NotNull(editedPropety); Assert.Equal(editedName, editedPropety.Name); }