Exemple #1
0
        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);
        }
Exemple #2
0
        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");
        }
Exemple #3
0
        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);
        }