Example #1
0
        public async Task SaveItemAsync_SaveServiceThrows_BadRequest_NameError()
        {
            var initialUom      = new Uom(1001, "in", "inch");
            var savedUom        = new Uom(1001, "", "inchy");
            var errorDictionary = new Dictionary <string, ReadOnlyCollection <string> >
            {
                ["Name"] = new ReadOnlyCollection <string>(new List <string> {
                    "Error1", "Error2"
                })
            };
            var exception = new BadRequestHttpException(errorDictionary);
            UomItemViewModel viewModel = new ViewModelTestBuilder <Uom>()
                                         .Then_ReadItemService_ReadItemAsync(initialUom)
                                         .Then_SaveItemService_SaveItemAsync_Throws(savedUom, UomEqual.Check, exception);
            await viewModel.GetItemAsync(1001);

            viewModel.Name        = "";
            viewModel.Description = "inchy";
            Assert.ThrowsAsync <BadRequestHttpException>
            (
                async() => await viewModel.SaveAsync()
            );
            Assert.True(UomItemViewModelEqual.Check
                        (
                            expected: savedUom,
                            expectedNameErrors: "Error1 Error2",
                            expectedDescriptionErrors: null,
                            actual: viewModel
                        ));
        }
Example #2
0
        public async Task SaveItemAsync_SaveServiceThrows_EmptyBadRequest()
        {
            var initialUom      = new Uom(1001, "in", "inch");
            var savedUom        = new Uom(1001, "in.", "");
            var errorDictionary = new Dictionary <string, ReadOnlyCollection <string> >
            {
                ["Description"] = new ReadOnlyCollection <string>(new List <string> {
                    ""
                })
            };
            var exception = new BadRequestHttpException(errorDictionary);
            UomItemViewModel viewModel = new ViewModelTestBuilder <Uom>()
                                         .Then_ReadItemService_ReadItemAsync(initialUom)
                                         .Then_SaveItemService_SaveItemAsync_Throws(savedUom, UomEqual.Check, exception);
            await viewModel.GetItemAsync(1001);

            viewModel.Name        = "in.";
            viewModel.Description = "";
            var actualException = Assert.ThrowsAsync <Exception>
                                  (
                async() => await viewModel.SaveAsync()
                                  );

            Assert.AreEqual(LrpConstants.NotSavedValidationProblem, actualException.Message);
        }