Example #1
0
        public void ControllerGetsProperPage(int currentPage, int itemsQuantity, int firstItemId)
        {
            var controllerContext = new ControllerContext();
            var httpContext       = new DefaultHttpContext();

            httpContext.Request.Headers.Add("x-requested-with", "");
            controllerContext.HttpContext = httpContext;
            var options = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(databaseName: "TestDb")
                          .Options;

            using (var context = new ApplicationDbContext(options))
            {
                context.Loot.AddRange(GetLootList());
                context.LootCategories.Add(new LootCategory {
                    LootCategoryName = "Test category"
                });
                context.SaveChanges();
                var controller = new LootController(context, null)
                {
                    ControllerContext = controllerContext
                };
                var result = controller.Index(pageNumber: currentPage, category: null) as ViewResult;
                var model  = result?.Model as List <Loot>;
                Assert.NotNull(model);
                Assert.Equal(itemsQuantity, model.Count);
                Assert.Equal(firstItemId, model[0].LootId);
            }
            using (var context = new ApplicationDbContext(options))
            {
                context.Database.EnsureDeleted();
            }
        }
Example #2
0
        public void ControllerSelectsProperItems(int categoryId, int itemsQuantity, int index)
        {
            var controllerContext = new ControllerContext();
            var httpContext       = new DefaultHttpContext();

            httpContext.Request.Headers.Add("x-requested-with", "");
            controllerContext.HttpContext = httpContext;
            var options = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(databaseName: "TestDb")
                          .Options;

            using (var context = new ApplicationDbContext(options))
            {
                context.Loot.AddRange(GetLootList());
                context.LootCategories.Add(new LootCategory {
                    LootCategoryName = "Test category"
                });
                context.SaveChanges();
                var controller = new LootController(context, null)
                {
                    ControllerContext = controllerContext
                };

                var result = controller.Index(categoryId, 1) as ViewResult;
                var model  = result.Model as List <Loot>;

                Assert.NotNull(model);
                Assert.Equal(itemsQuantity, model.Count);
                Assert.Equal(GetLootList()[index],
                             model[0],
                             Comparer <Loot> .GetComparer((loot1, loot2) => loot1.LootCategoryId == loot2.LootCategoryId));
            }
            using (var context = new ApplicationDbContext(options))
            {
                context.Database.EnsureDeleted();
            }
        }
Example #3
0
        public void Store2()
        {
            // ARRANGE
            var handlerMock = new Mock <HttpMessageHandler>(MockBehavior.Strict);

            handlerMock
            .Protected()
            // Setup the PROTECTED method to mock
            .Setup <Task <HttpResponseMessage> >(
                "SendAsync",
                ItExpr.IsAny <HttpRequestMessage>(),
                ItExpr.IsAny <CancellationToken>()
                )
            // prepare the expected response of the mocked http call
            .ReturnsAsync(new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.OK,
                Content    = null,
            })
            .Verifiable();

            var httpClient = new HttpClient(handlerMock.Object)
            {
                BaseAddress = new Uri("http://test.com/"),
            };
            var subjectUnderTest = new EquipmentController(httpClient, new Web.MyConfiguration()
            {
                ServiceUrl = "http://test.com/"
            });

            var result  = subjectUnderTest.Index();
            var result2 = subjectUnderTest.Create();
            var result3 = subjectUnderTest.Create(new EquipmentModel());
            var result4 = subjectUnderTest.Edit(new EquipmentModel());
            var result5 = subjectUnderTest.Edit(1, 2, "", "", 2, 3, 3);

            var subjectUnderTest2 = new LocationController(httpClient, new Web.MyConfiguration()
            {
                ServiceUrl = "http://test.com/"
            });
            var result6  = subjectUnderTest2.Index();
            var result7  = subjectUnderTest2.Create();
            var result8  = subjectUnderTest2.Create(new LocationModel());
            var result9  = subjectUnderTest2.EditLoot(1, 1, 1, "", 1, "");
            var result10 = subjectUnderTest2.EditLoot(new LootModel());
            var result11 = subjectUnderTest2.EditLocation(new LocationModel());
            var result12 = subjectUnderTest2.EditLocation(1, "", "", 1);
            var result13 = subjectUnderTest2.Delete(1);

            var subjectUnderTest3 = new HomeController();

            subjectUnderTest3.Index();
            subjectUnderTest3.Privacy();


            var subjectUnderTest4 = new LootController(httpClient, new Web.MyConfiguration()
            {
                ServiceUrl = "http://test.com/"
            });
            var result17          = subjectUnderTest4.Index();
            var subjectUnderTest5 = new PlayerController(httpClient, new Web.MyConfiguration()
            {
                ServiceUrl = "http://test.com/"
            });
            var result18 = subjectUnderTest5.Index();
            var result19 = subjectUnderTest5.Edit(1, 2, "", "", 1, 1);
            var result20 = subjectUnderTest5.Edit(new LootModel());
            var result21 = subjectUnderTest5.EditPlayer(1, "", 1);
            var result22 = subjectUnderTest5.EditPlayer(new PlayerModel());
            var result23 = subjectUnderTest5.EditEquipment(1, 1, "", "", 1, 1, 1);
            var result24 = subjectUnderTest5.EditEquipment(new EquipmentModel());
            var result25 = subjectUnderTest5.Delete(1, new LootModel());
            var result26 = subjectUnderTest5.Delete(1);
            var result27 = subjectUnderTest5.DeleteEquipment(1, new EquipmentModel());

            Assert.NotNull(subjectUnderTest);
        }