Exemple #1
0
        public void VaultListInputWebUserReturnsView()
        {
            Mock <IVaultManager> mockVaultManager = new Mock <IVaultManager>();
            var target = new VaultController(mockVaultManager.Object, null, null);

            var result = target.VaultList(new WebUser());

            mockVaultManager.Verify(x => x.GetVaults(It.IsAny <string>()), Times.Once);
            Assert.IsInstanceOfType(result, typeof(PartialViewResult));
        }
Exemple #2
0
 void Awake()
 {
     if (VaultController.instance == null)
     {
         instance = this;
     }
     else if (VaultController.instance != this)
     {
         Destroy(this.gameObject);
     }
 }
Exemple #3
0
        public async Task DeleteGeneratesExceptionReturnView()
        {
            Mock <IVaultManager> mockVaultManager = new Mock <IVaultManager>();

            mockVaultManager.Setup(x => x.DeleteAsync(It.IsAny <string>())).Throws <SystemException>();
            var target = new VaultController(mockVaultManager.Object, null, null);

            var result = await target.Delete(new WebUser(), "1");

            Assert.IsInstanceOfType(result, typeof(ViewResult));
        }
Exemple #4
0
        public void CreateInputWebUserReturnView()
        {
            Mock <IVaultManager> mockVaultManager = new Mock <IVaultManager>();
            var target = new VaultController(mockVaultManager.Object, null, null);

            var result = target.Create(new WebUser());
            var model  = (UserVault)((ViewResult)result).Model;

            Assert.IsNotNull(model);
            Assert.IsNotNull(model.AllowCreate);
            Assert.IsNotNull(model.AllowRead);
            Assert.IsInstanceOfType(result, typeof(ViewResult));
        }
Exemple #5
0
        public async Task CreateInputWebuserUservaultReturnView()
        {
            Mock <IVaultManager> mockVaultManager = new Mock <IVaultManager>();
            var target = new VaultController(mockVaultManager.Object, null, null);

            target.ModelState.AddModelError("", "");

            var result = await target.Create(new WebUser()
            {
                Id = "1", UserName = "******"
            }, new UserVault());

            var model = ((ViewResult)result).Model as UserVault;

            Assert.IsNotNull(model);
            Assert.AreEqual(model.VaultAdmin.Id, "1");
            Assert.IsInstanceOfType(result, typeof(ViewResult));
        }
Exemple #6
0
        public async Task CreateInputWebuserUservaultReturnError()
        {
            Mock <IVaultManager> mockVaultManager = new Mock <IVaultManager>();

            mockVaultManager.Setup(x => x.CreateAsync(It.IsAny <UserVault>())).ThrowsAsync(new SystemException());
            var target = new VaultController(mockVaultManager.Object, null, null);
            var user   = new WebUser()
            {
                Id = "1", UserName = "******"
            };

            var result = await target.Create(user, new UserVault()
            {
                Name = "TestVault"
            });

            Assert.IsInstanceOfType(result, typeof(ViewResult));
            Assert.AreEqual(((ViewResult)result).ViewName, "Error");
        }
Exemple #7
0
        public async Task CreateInputWebuserUservaultReturnRedirect()
        {
            Mock <IVaultManager> mockVaultManager = new Mock <IVaultManager>();
            var target = new VaultController(mockVaultManager.Object, null, null);
            var user   = new WebUser()
            {
                Id = "1", UserName = "******"
            };

            var result = await target.Create(user, new UserVault()
            {
                Name = "TestVault"
            });

            var model = ((RedirectToRouteResult)result);

            mockVaultManager.Verify(x => x.CreateAsync(It.IsAny <UserVault>()), Times.Once);
            Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult));
            Assert.AreEqual(model.RouteValues["action"], "Index");
        }
Exemple #8
0
        public async Task DeleteEqualUserIdsRedirectNoSuccess()
        {
            Mock <IVaultManager> mockVaultManager = new Mock <IVaultManager>();
            var vault = new UserVault()
            {
                Id = "1", VaultAdmin = new VaultUser()
                {
                    Id = "1"
                }
            };

            mockVaultManager.Setup(x => x.GetVaultAdmin(vault.Id)).ReturnsAsync(vault.VaultAdmin);
            var target = new VaultController(mockVaultManager.Object, null, null);

            var result = await target.Delete(new WebUser()
            {
                Id = "2"
            }, vault.Id);

            Assert.AreEqual(((RedirectToRouteResult)result).RouteValues["action"], "Index");
        }
Exemple #9
0
        public async Task DeleteNonequalUserIdsReturnRedirectSuccess()
        {
            Mock <IVaultManager> mockVaultManager = new Mock <IVaultManager>();
            var vault = new UserVault()
            {
                Id = "1", VaultAdmin = new VaultUser()
                {
                    Id = "1"
                }
            };

            mockVaultManager.Setup(x => x.GetVaultAdmin(vault.Id)).ReturnsAsync(vault.VaultAdmin);
            var target = new VaultController(mockVaultManager.Object, null, null);

            var result = await target.Delete(new WebUser()
            {
                Id = "1"
            }, vault.Id);

            mockVaultManager.Verify(x => x.DeleteAsync(It.IsAny <string>()), Times.Once);
            Assert.IsNotNull(target.TempData["message"]);
            Assert.AreEqual(((RedirectToRouteResult)result).RouteValues["action"], "Index");
        }