private async Task TestEmptyValidation(Expression <Func <Medication, string> > fieldSelector, string field, [CallerMemberName] string name = null) { var controller = new MedicationsController(CreateDatabase(name)); var testItem = _fixture.Build <Medication>().With(fieldSelector, "").Create(); var result = await controller.AddMedication(testItem); result.Should().BeIsBlankResultForPath(field); }
public async Task CreateReturnsBadRequestOnDuplicationName() { var items = PopulateDatabaseWithItems(); var controller = new MedicationsController(CreateDatabase()); var testItem = _fixture.Build <Medication>().With(m => m.Name, items.First().Name).Create(); var result = await controller.AddMedication(testItem); result.Should().BeIsInUseResultForPath("name"); }
public async Task CreateReturnsAddsItemOnGoodRequest() { PopulateDatabaseWithItems(); var controller = new MedicationsController(CreateDatabase()); var testItem = _fixture.Create <Medication>(); var result = await controller.AddMedication(testItem); var newItem = await CreateDatabase().Medications.FirstOrDefaultAsync(m => m.Name == testItem.Name); testItem.Id = newItem.Id; newItem.Should().BeEquivalentTo(testItem); result.Should().BeCreatedResultWithValue($"/api/get-medication/{testItem.Id}", newItem); }