예제 #1
0
                public async Task WhenStreingerReturnNULLResultExeption()
                {
                    var strngr = new Mock <IStreinger>();

                    strngr.Setup(ex => ex.Goods()).Returns(Task.FromResult((IEnumerable <Good>)null));

                    var algo   = new TopAlgorithm();
                    var search = new preparation.Controllers.SearchController(streinger: strngr.Object, topAlgorithm: algo);

                    NUnitAssert.CatchAsync(async() => await search.Index());
                }
예제 #2
0
                public async Task WhenStreingerReturnOKDataResultOKModel()
                {
                    var algo   = new TopAlgorithm();
                    var search = new preparation.Controllers.SearchController(streinger: strngr, topAlgorithm: algo);

                    var resp = await search.Index();

                    NUnitAssert.IsAssignableFrom(typeof(ViewResult), resp);
                    NUnitAssert.NotNull(resp);

                    var model = (resp as ViewResult).ViewData.Model;

                    NUnitAssert.NotNull(model);
                    NUnitAssert.IsAssignableFrom <IEnumerable <IProduct>[]>(model);
                }
예제 #3
0
            public async Task GetTopWhenDataIsnotEmpty()
            {
                //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"
                        }
                    },
                };
                IEnumerable <IEnumerable <IProduct> > expected = new[]
                {
                    new[] { goods[0] },
                    new[] { goods[1] },
                };

                var mok = new Mock <IStreinger>();

                mok.Setup(m => m.Goods())
                .ReturnsAsync(goods);
                var algorighm = new Mock <TopAlgorithm>();

                algorighm.Setup(a => a.Top(It.IsAny <IEnumerable <IEnumerable <IProduct> > >()))
                .Returns(expected);

                var seachController = new preparation.Controllers.SearchController(mok.Object, algorighm.Object);

                //Actual
                var resp = await seachController.Index();

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

                Assert.Equal(expected, model);
            }
예제 #4
0
            public async Task GetTopWhenDataIsEmpty()
            {
                //Arrange
                IEnumerable <Good> goods = new Good[] { };
                var mok = new Mock <IStreinger>();

                mok.Setup(m => m.Goods())
                .ReturnsAsync(goods);
                var algorighm = new Mock <TopAlgorithm>();

                algorighm.Setup(a => a.Top(It.IsAny <IEnumerable <IEnumerable <IProduct> > >()))
                .Returns((IEnumerable <IEnumerable <IProduct> >)null);

                var seachController = new preparation.Controllers.SearchController(mok.Object, algorighm.Object);

                //Actual
                var resp = await seachController.Index();

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

                Assert.Null(viewResult.ViewData.Model);
            }
예제 #5
0
                public async Task WhenCompanyNameOrProductNameNullResultExeption()
                {
                    var goods = new Good[]
                    {
                        new Good()
                        {
                            Product = new Preparation()
                            {
                            },
                            Supplier = new Supplier()
                            {
                            }
                        }
                    }.AsEnumerable();

                    var strngr = new Mock <IStreinger>();

                    strngr.Setup(ex => ex.Goods()).Returns(Task.FromResult(goods));

                    var algo   = new TopAlgorithm();
                    var search = new preparation.Controllers.SearchController(streinger: strngr.Object, topAlgorithm: algo);

                    NUnitAssert.CatchAsync <ArgumentNullException>(async() => await search.Index());
                }