Example #1
0
 public void SutIsProductRepository(SecureProductRepository sut)
 {
     // Fixture setup
     // Exercise system
     // Verify outcome
     Assert.IsAssignableFrom <ProductRepository>(sut);
     // Teardown
 }
Example #2
0
 public void InsertProductWillThrowWhenPrincipalIsNotInRequiredRole(SecureProductRepository sut, Product p)
 {
     // Fixture setup
     Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity(string.Empty), null);
     // Exercise system and verify outcome
     Assert.Throws <SecurityException>(() =>
                                       sut.InsertProduct(p));
     // Teardown
 }
Example #3
0
        public void Add_InsufficientSecurityLevel_Throws()
        {
            var environment = new Mock <IEnvironment>();

            environment.SetupGet(env => env.User).Returns(new User {
                Level = SecurityLevel.User, UserName = "******"
            });
            var secureRepo = new SecureProductRepository(new Mock <IProductRepository>().Object, environment.Object);

            Assert.Throws <NotAuthorizedException>(() => secureRepo.Add(new Product {
                Id = 1, Name = "Product A", Price = 5.99m
            }));
        }
Example #4
0
 public void InsertProductWillInsertProductIntoDecoratedRepositoryWhenPrincipalIsInCorrectRole([Frozen] Mock <ProductRepository> repositoryMock,
                                                                                               GenericIdentity id, Product product, SecureProductRepository sut)
 {
     // Fixture setup
     Thread.CurrentPrincipal = new GenericPrincipal(id, new[] { "ProductManager" });
     // Exercise system
     sut.InsertProduct(product);
     // Verify outcome
     repositoryMock.Verify(r => r.InsertProduct(product));
     // Teardown
 }