コード例 #1
0
        public ConfigurationTests()
        {
            context       = TestingContext.Create();
            configuration = new Configuration(context);

            context.Drop();
        }
コード例 #2
0
        public RoleServiceTests()
        {
            context = TestingContext.Create();
            service = Substitute.ForPartsOf <RoleService>(new UnitOfWork(TestingContext.Create()));

            role = SetUpData();
        }
コード例 #3
0
        public void OnResourceExecuted_Exception_Rollbacks()
        {
            ActionContext           action  = new(new DefaultHttpContext(), new RouteData(), new ActionDescriptor());
            ResourceExecutedContext context = new(action, Array.Empty <IFilterMetadata>());

            using DbContext currentContext = TestingContext.Create();
            using DbContext testingContext = TestingContext.Create();
            Role role = ObjectsFactory.CreateRole(0);

            context.Exception = new Exception();

            testingContext.Drop();

            TransactionFilter filter = new(testingContext);

            testingContext.Add(role);
            testingContext.SaveChanges();

            Assert.Empty(currentContext.Set <Role>());
            Assert.Single(testingContext.Set <Role>());

            filter.OnResourceExecuted(context);

            Assert.Empty(currentContext.Set <Role>());
            Assert.Empty(testingContext.Set <Role>());
        }
コード例 #4
0
        public QueryTests()
        {
            context = TestingContext.Create();
            select  = new Query <Role>(context.Set <Role>(), TestingContext.Mapper.ConfigurationProvider);

            context.Drop().Add(ObjectsFactory.CreateRole(0));
            context.SaveChanges();
        }
コード例 #5
0
        public UnitOfWorkTests()
        {
            context    = TestingContext.Create();
            model      = ObjectsFactory.CreateRole(0);
            unitOfWork = new UnitOfWork(context);

            context.Drop();
        }
コード例 #6
0
        public void OnResourceExecuting_DoesNothing()
        {
            using DbContext testingContext = TestingContext.Create();
            ActionContext            action  = new(new DefaultHttpContext(), new RouteData(), new ActionDescriptor());
            ResourceExecutingContext context = new(action, Array.Empty <IFilterMetadata>(), Array.Empty <IValueProviderFactory>());

            new TransactionFilter(testingContext).OnResourceExecuting(context);
        }
コード例 #7
0
        public RoleValidatorTests()
        {
            context   = TestingContext.Create();
            validator = new RoleValidator(new UnitOfWork(TestingContext.Create()));

            context.Drop().Add(role = ObjectsFactory.CreateRole(0));
            context.SaveChanges();
        }
コード例 #8
0
        public QueryTests()
        {
            context = TestingContext.Create();
            select  = new Query <Role>(context.Set <Role>());

            context.Drop().Add(ObjectsFactory.CreateRole(0));
            context.SaveChanges();
        }
コード例 #9
0
        public AuditedUnitOfWorkTests()
        {
            context    = TestingContext.Create();
            model      = ObjectsFactory.CreateRole(0);
            unitOfWork = new AuditedUnitOfWork(context, 1);

            context.Drop().Add(model);
            context.SaveChanges();
        }
コード例 #10
0
        public AuthorizationTests()
        {
            context  = TestingContext.Create();
            services = Substitute.For <IServiceProvider>();

            services.GetService(typeof(IAuthorization)).Returns(Substitute.For <IAuthorization>());
            services.GetService(typeof(IUnitOfWork)).Returns(_ => new UnitOfWork(TestingContext.Create()));

            authorization = new Authorization(Assembly.GetExecutingAssembly(), services);
        }
コード例 #11
0
        public AccountValidatorTests()
        {
            context = TestingContext.Create();
            hasher  = Substitute.For <IHasher>();
            hasher.VerifyPassword(Arg.Any <String>(), Arg.Any <String>()).Returns(true);
            validator = new AccountValidator(new UnitOfWork(TestingContext.Create(), TestingContext.Mapper), hasher);

            context.Drop().Add(account = ObjectsFactory.CreateAccount(0));
            context.SaveChanges();
        }
コード例 #12
0
        public LoggableEntityTests()
        {
            using (context = TestingContext.Create())
            {
                context.Drop().Add(model = ObjectsFactory.CreateRole(0));
                context.SaveChanges();
            }

            context = TestingContext.Create();
            entry = context.Entry<AModel>(model);
        }
コード例 #13
0
ファイル: LoggablePropertyTests.cs プロジェクト: mdy6/ToDoApp
        public LoggablePropertyTests()
        {
            Role model = new() { Id = 1 };

            using DbContext context = TestingContext.Create();

            context.Set <Role>().Attach(model);
            context.Entry(model).State = EntityState.Modified;
            textProperty = context.Entry(model).Property(prop => prop.Title);
            dateProperty = context.Entry(model).Property(prop => prop.CreationDate);
        }
コード例 #14
0
ファイル: AccountServiceTests.cs プロジェクト: mdy6/ToDoApp
        public AccountServiceTests()
        {
            context     = TestingContext.Create();
            hasher      = Substitute.For <IHasher>();
            httpContext = new DefaultHttpContext();
            service     = new AccountService(new UnitOfWork(TestingContext.Create(), TestingContext.Mapper), hasher);

            hasher.HashPassword(Arg.Any <String>()).Returns(info => $"{info.Arg<String>()}Hashed");
            context.Drop().Add(account = ObjectsFactory.CreateAccount(0));
            context.SaveChanges();
        }
コード例 #15
0
        public void Resources_HasAllPermissionControllerTitles()
        {
            using DbContext context           = TestingContext.Create();
            using Configuration configuration = new(context);

            configuration.Seed();

            foreach (String path in context.Set <Permission>().Select(permission => $"{permission.Area}/{permission.Controller}").Distinct())
            {
                Assert.True(Resource.ForController(path) != "", $"'{path}' permission does not have a title.");
            }
        }
コード例 #16
0
        public void Resources_HasAllPermissionAreaTitles()
        {
            using DbContext context           = TestingContext.Create();
            using Configuration configuration = new(context);

            configuration.Seed();

            foreach (String area in context.Set <Permission>().Select(permission => permission.Area).Where(area => area != "").Distinct())
            {
                Assert.True(Resource.ForArea(area) != "", $"'{area}' area does not have a title.");
            }
        }
コード例 #17
0
        public void Resources_HasAllPermissionActionTitles()
        {
            using DbContext context           = TestingContext.Create();
            using Configuration configuration = new(context);

            configuration.Seed();

            foreach (String name in context.Set <Permission>().Select(permission => permission.Action).Distinct())
            {
                Assert.True(Resource.ForAction(name) != "", $"'{name}' action does not have a title.");
            }
        }
コード例 #18
0
        public void Commit_AddedAudit()
        {
            context.Dispose();
            unitOfWork.Dispose();
            context    = TestingContext.Create();
            unitOfWork = new AuditedUnitOfWork(context, 1);
            unitOfWork.Insert(ObjectsFactory.CreateRole(1));

            LoggableEntity expected = new(context.ChangeTracker.Entries <AModel>().Single());

            unitOfWork.Commit();

            AuditLog actual = Assert.Single(unitOfWork.Select <AuditLog>());

            Assert.Equal(expected.ToString(), actual.Changes);
            Assert.Equal(expected.Name, actual.EntityName);
            Assert.Equal(expected.Action, actual.Action);
            Assert.Equal(expected.Id(), actual.EntityId);
            Assert.Equal(1, actual.AccountId);
        }