Exemplo n.º 1
0
            public async Task SearchWhenProductDoesntExist()
            {
                //Arrange
                var goods = new[]
                {
                    new Good()
                    {
                        Price = 2.12m, Product = new Preparation()
                        {
                            Name = "_world_"
                        }
                    }
                };
                var mok = new Mock <IStreinger>();

                mok.Setup(m => m.Goods())
                .ReturnsAsync(goods);
                var seachController = new preparation.Controllers.SearchController(mok.Object, null);

                //Actual
                var resp = await seachController.Search("_not_found");

                //Assert
                var viewResult = Assert.IsType <ViewResult>(resp);
                var model      = viewResult.ViewData.Model;

                Assert.Null(model);
            }
Exemplo n.º 2
0
            public async Task SearchWhenInputIsEmptyStr()
            {
                //Arrange
                var mok = new Mock <IExternalDb>();

                mok.Setup(e => e.AskService(It.IsAny <string>(), It.IsAny <HttpMethod>(), It.IsAny <(string, string)>()))
                .Returns(Task.FromResult(""));
                var streinger = new Streinger(mok.Object);

                var    seachController = new preparation.Controllers.SearchController(streinger, null);
                string preparationName = "";
                //Actual
                var resp = await seachController.Search(preparationName);

                //Assert
                var viewResult = Assert.IsType <ViewResult>(resp);

                Assert.Null(viewResult.ViewData.Model);
            }
Exemplo n.º 3
0
            public async Task SearchWhenProductExists()
            {
                //Arrange
                var goods = new[]
                {
                    new Good()
                    {
                        Price = 2.12m, Product = new Preparation()
                        {
                            Name = "_world_"
                        }
                    },
                    new Good()
                    {
                        Price = 12.2m, Product = new Preparation()
                        {
                            Name = "hello_world"
                        }
                    },
                };
                var mok = new Mock <IStreinger>();

                mok.Setup(m => m.Goods())
                .ReturnsAsync(goods);
                var seachController = new preparation.Controllers.SearchController(mok.Object, null);

                IEnumerable <IEnumerable <IProduct> > expected = new[]
                {
                    new[] { goods[0] },
                    new[] { goods[1] },
                };

                //Actual
                var resp = await seachController.Search("_world");

                //Assert
                var viewResult = Assert.IsType <ViewResult>(resp);
                IEnumerable <IEnumerable <IProduct> > model =
                    Assert.IsAssignableFrom <IEnumerable <IEnumerable <IProduct> > >(viewResult.ViewData.Model);

                Assert.Equal(expected, model);
            }