public async Task SoftDelete_WhenMeasureTypeExists() { // Arrange contextOptions = new DbContextOptionsBuilder <SmartDormitoryContext>() .UseInMemoryDatabase(databaseName: "SoftDelete_WhenMeasureTypeExists") .Options; var existingId = Guid.NewGuid().ToString(); var existingMeasureUnit = "Some existing measure unit"; var existingSuitableSensorType = "Some existing sensor type"; using (var arrangeContext = new SmartDormitoryContext(contextOptions)) { await arrangeContext.MeasureTypes.AddAsync( new MeasureType { Id = existingId, MeasureUnit = existingMeasureUnit, SuitableSensorType = existingSuitableSensorType, IsDeleted = false }); await arrangeContext.SaveChangesAsync(); } // Act && Asert using (var assertContext = new SmartDormitoryContext(contextOptions)) { var sut = new MeasureTypeService(assertContext); await sut.DeleteType(existingId); Assert.IsTrue(assertContext.MeasureTypes.Any(mt => mt.Id == existingId && mt.IsDeleted == true)); } }
public async Task ThrowsEntityDoesntExistException_WhenDoesntExists() { // Arrange contextOptions = new DbContextOptionsBuilder <SmartDormitoryContext>() .UseInMemoryDatabase(databaseName: "ThrowsEntityDoesntExistException_WhenDoesntExists") .Options; var inexistingId = Guid.NewGuid().ToString(); // Act && Asert using (var assertContext = new SmartDormitoryContext(contextOptions)) { var sut = new MeasureTypeService(assertContext); await Assert.ThrowsExceptionAsync <EntityDoesntExistException>( () => sut.DeleteType(inexistingId), "\nMeasure Type doesn't exists!"); } }