Ejemplo n.º 1
0
        private async Task TestUpdateValidation(Expression <Func <Medication, string> > fieldSelector, string field, [CallerMemberName] string name = null)
        {
            var items      = PopulateDatabaseWithItems(name);
            var controller = new MedicationsController(CreateDatabase(name));

            var testItem = items.First();

            var updateItem = _fixture.Build <Medication>().With(fieldSelector, "").Create();

            var result = await controller.UpdateMedication(testItem.Id, updateItem);

            result.Should().BeIsBlankResultForPath(field);
        }
Ejemplo n.º 2
0
        private async Task UpdateHandlesInputModel(bool goodId = true, bool duplicateName = false, [CallerMemberName] string name = null)
        {
            var items = PopulateDatabaseWithItems(name);

            var controller = new MedicationsController(CreateDatabase(name));

            var testItem = _fixture.Create <Medication>();

            var oldItem    = items.OrderBy(m => m.Id).First();
            var secondItem = items.OrderBy(m => m.Id).Skip(1).First();

            var oldId = goodId ? oldItem.Id : -1;

            if (duplicateName)
            {
                testItem.Name = secondItem.Name;
            }

            var result = await controller.UpdateMedication(oldId, testItem);

            var newItem = await CreateDatabase(name).Medications.FirstOrDefaultAsync(m => m.Id == oldItem.Id);

            if (goodId && !duplicateName)
            {
                testItem.Id = oldId;

                newItem.Should().BeEquivalentTo(testItem);

                result.Should().BeOkResultWithValue(newItem);
            }
            else
            {
                newItem.Should().BeEquivalentTo(oldItem);

                if (duplicateName)
                {
                    result.Should().BeIsInUseResultForPath("name");
                }
                else
                {
                    result.Should().BeOfType <NotFoundResult>();
                }
            }
        }