Пример #1
0
        public void TestMethodGet()
        {
            var context = new TestBankDBContext();

            context.Banks.Add(GetSingleItem());

            var controller = new BanksController(context);
            var result     = controller.GetBank(1) as OkNegotiatedContentResult <Bank>;

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Content.Id);
        }
Пример #2
0
        public void TestMethodGetSave()
        {
            var controller = new BanksController(new TestBankDBContext());

            var item = GetSingleItem();

            var result =
                controller.PostBank(item) as CreatedAtRouteNegotiatedContentResult <Bank>;

            Assert.IsNotNull(result);
            Assert.AreEqual(result.RouteName, "DefaultApi");
            Assert.AreEqual(result.RouteValues["id"], result.Content.Id);
            Assert.AreEqual(result.Content.Name, item.Name);
        }
Пример #3
0
        public BanksControllerTests()
        {
            var services = MockServices.ScopedServiceProvider;

            _controller = new BanksController(
                services.GetService <IGuildBankManager>(),
                services.GetService <IDiscordClient>())
            {
                ControllerContext = new ControllerContext
                {
                    HttpContext = new DefaultHttpContext {
                        User = new ClaimsPrincipal(new ClaimsIdentity())
                    }
                }
            };
        }
        public async void Test_Get_DeleteBank()
        {
            var mock = new Mock <IBankService>();

            mock.Setup(p => p.Remove(It.IsAny <String>())).Returns(Task.FromResult <Result>(new Result()
            {
                IsSuccess = true, Message = "Bank Record Deleted"
            }));
            BanksController controller = new BanksController(mock.Object);
            var             result     = await controller.Delete(Guid.NewGuid().ToString());

            var actionResult = Assert.IsType <ActionResult <Result> >(result);
            var objectResult = Assert.IsType <OkObjectResult>(actionResult.Result);
            var returnResult = Assert.IsType <Result>(objectResult.Value);

            Assert.True(returnResult.IsSuccess);
        }
        public async void Test_Get_Bank()
        {
            var mock = new Mock <IBankService>();

            mock.Setup(p => p.Get(It.IsAny <string>())).Returns(Task.FromResult <Bank>(new Bank()
            {
                Id = Guid.NewGuid().ToString(), Name = "RoyalBank"
            }));
            BanksController controller = new BanksController(mock.Object);
            var             result     = await controller.GetBank(Guid.NewGuid().ToString());

            var actionResult = Assert.IsType <ActionResult <Bank> >(result);
            var objectResult = Assert.IsType <OkObjectResult>(actionResult.Result);
            var bank         = Assert.IsType <Bank>(objectResult.Value);

            Assert.Equal("RoyalBank", bank.Name);
        }
Пример #6
0
        public void TestMethodGetList()
        {
            var context = new TestBankDBContext();

            context.Banks.Add(new Bank {
                Id = 1, Name = "BPD", Street = "Av. Maximo Gomez", ZipCode = "784578", UserId = 1, CreatedOn = DateTime.Now
            });
            context.Banks.Add(new Bank {
                Id = 2, Name = "BHD", Street = "Av. Winston Churchill", ZipCode = "457845", UserId = 1, CreatedOn = DateTime.Now
            });
            context.Banks.Add(new Bank {
                Id = 3, Name = "Banreservas", Street = "Av. Winston Churchill", ZipCode = "356564", UserId = 1, CreatedOn = DateTime.Now
            });

            var controller = new BanksController(context);
            var result     = controller.GetBanks() as TestBankDbSet;

            Assert.IsNotNull(result);
            Assert.AreEqual(3, result.Local.Count);
        }
Пример #7
0
        public BankServiceMoq()
        {
            Mock <IBankService> _bankRepository = new BankRepositoryMoq()._bankRepository;

            _banksController = new BanksController(_bankRepository.Object);
        }