public async Task IntegrityTest() { _controller.User.SetId(Dummies.Alice.Id); var res = await _controller.ListBanks(Dummies.GuildA.Id); var items = (IEnumerable <ApiGuildBank>)((ObjectResult)res).Value; Assert.Empty(items); res = (ObjectResult)await _controller.CreateBank(Dummies.GuildA.Id, new ApiGuildBank(new GuildBank(Dummies.GuildA.Id, "Bank1") { ModeratorRoleId = 2 })); var bank = (ApiGuildBank)((ObjectResult)res).Value; Assert.Equal("Bank1", bank.Name); Assert.NotNull(bank.ModeratorRoleId); Assert.Equal(2ul, bank.ModeratorRoleId !.Value); Assert.Equal(1ul, bank.GuildId); Assert.Equal(1, bank.Id); // Test invariance of bankId. res = await _controller.EditBank(1, 1, new GuildBank(1, "NewName") { Id = 999, ModeratorRoleId = null }); Assert.IsType <OkResult>(res); res = await _controller.GetBank(1, 1); bank = (ApiGuildBank)((ObjectResult)res).Value; Assert.Equal("NewName", bank.Name); Assert.Null(bank.ModeratorRoleId); Assert.Equal(1, bank.Id); res = await _controller.ListBanks(1); items = (IEnumerable <ApiGuildBank>)((ObjectResult)res).Value; Assert.NotEmpty(items); res = await _controller.RemoveBank(1, 1); Assert.IsType <NoContentResult>(res); res = await _controller.ListBanks(1); items = (IEnumerable <ApiGuildBank>)((ObjectResult)res).Value; Assert.Empty(items); }
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); }
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); }