예제 #1
0
 public void InitializeTest()
 {
     CurrentUser = new EducationSecurityPrincipal(new User {
         Id = 39, UserKey = "39"
     });
     MockRequest = MockHttpContextFactory.CreateRequest();
 }
예제 #2
0
 public void BaseInitializeTest()
 {
     User = new EducationSecurityPrincipal(new User {
         UserKey = "whatever"
     });
     MockHttpContext = MockHttpContextFactory.Create();
 }
 public void InitializeTest()
 {
     MockContext = MockHttpContextFactory.Create();
     TestData    = new TestData();
     User        = new EducationSecurityPrincipal(new User {
         UserKey = "whatever"
     });
 }
예제 #4
0
        public void WhenGenerateDataTableResultViewModel_ThenSucceed()
        {
            EducationSecurityPrincipal user      = new EducationSecurityPrincipal(EducationContext.Users.First());
            DataTableRequestModel      model     = new DataTableRequestModel();
            ProviderClientDataTable    dataTable = new ProviderClientDataTable(MockHttpContextFactory.CreateRequest(), user);

            Target.GenerateDataTableResultViewModel(model, dataTable);
        }
        private TestClientDataTable CreateTarget(int?sortColumnIndex, string sortDirection)
        {
            HttpRequestBase request = MockHttpContextFactory.CreateRequest();

            request.Expect(m => m["iSortCol_0"]).Return(sortColumnIndex.HasValue ? sortColumnIndex.Value.ToString() : null);
            request.Expect(m => m["sSortDir_0"]).Return(sortDirection);
            return(new TestClientDataTable(request));
        }
예제 #6
0
 public void InitializeTest()
 {
     EducationContext = new EducationDataContext();
     Container = AssemblySetup.CreateWindsorContainer(EducationContext);
     RepositoryContainer repositoryContainer = new RepositoryContainer(Container, EducationContext);
     Target = new SchoolDistrictManager(repositoryContainer, new DataTableBinder(), new UserAuditor());
     User = new EducationSecurityPrincipal(EducationContext.Users.Include("UserRoles.Role").Single(u => u.UserKey == "Bob"));
     MockContext = MockHttpContextFactory.Create();
 }
        public void GivenIControllerType_WhenICreateController_ThenContructTheType()
        {
            RequestContext request        = new RequestContext(MockHttpContextFactory.Create(), new RouteData());
            IController    expected       = new TestController();
            Type           controllerType = expected.GetType();

            Kernel.Expect(m => m.Resolve(controllerType)).Return(expected);
            IController actual = Target.ExecuteGetControllerInstance(request, controllerType);

            Assert.AreEqual(expected, actual);
        }
예제 #8
0
        public void WhenGenerateDataTableResultViewModel_ThenSucceed()
        {
            DataTableRequestModel model = new DataTableRequestModel {
                iDisplayLength = 10
            };
            User userEntity = EducationContext.Users.First(u => u.UserRoles.Select(ur => ur.Role).Any(r => r.Name == SecurityRoles.DataAdmin));
            EducationSecurityPrincipal user      = new EducationSecurityPrincipal(userEntity);
            ServiceTypeClientDataTable dataTable = new ServiceTypeClientDataTable(MockHttpContextFactory.CreateRequest(), user);

            Target.GenerateDataTableResultViewModel(model, dataTable);
        }
 public void BaseInitializeTest()
 {
     User = new EducationSecurityPrincipal(new User {
         UserKey = "whatever"
     });
     Data                = new TestData();
     Repositories        = new TestRepositories(Data);
     MockHttpContext     = MockHttpContextFactory.Create();
     MockDataTableBinder = MockRepository.GenerateMock <IDataTableBinder>();
     PermissionFactory.SetCurrent(MockRepository.GenerateMock <IPermissionFactory>());
 }
        public void WhenGenerateDataTableResultViewModel_ThenViewModelContainsData()
        {
            HttpContextBase       mockHttpContext = MockHttpContextFactory.Create();
            DataTableRequestModel viewModel       = new DataTableRequestModel {
                iDisplayLength = 10
            };
            UserClientDataTable dataTable = new UserClientDataTable(mockHttpContext.Request, new DefaultSecurityConfiguration());

            DataTableResultModel actual = Target.GenerateDataTableResultViewModel(viewModel, dataTable);

            Assert.AreNotEqual(0, actual.aaData.Count());
        }
            public UserHttpContext(string userKey)
            {
                var claim         = new System.Security.Claims.Claim(System.Security.Claims.ClaimTypes.NameIdentifier, userKey);
                var claimIdentity = new System.Security.Claims.ClaimsIdentity(new List <System.Security.Claims.Claim> {
                    claim
                }, "Test");
                var identity  = new System.Security.Claims.ClaimsIdentity[] { claimIdentity };
                var principal = new System.Security.Claims.ClaimsPrincipal(identity);

                User      = principal;
                _Request  = MockHttpContextFactory.CreateRequest();
                _Response = MockHttpContextFactory.CreateResponse();
            }
        public void GivenSort_WhenGenerateDataTableResultViewModel_ThenSucceed()
        {
            DataTableRequestModel model = new DataTableRequestModel();

            model.iDisplayLength = 10;
            var request = MockHttpContextFactory.CreateRequest();

            request.Expect(r => r["id"]).Return("1");
            request.Expect(r => r["iSortCol_0"]).Return("0");
            request.Expect(r => r["sSortDir_0"]).Return("asc");
            ServiceAttendanceClientDataTable dataTable = new ServiceAttendanceClientDataTable(request);

            var actual = Target.GenerateDataTableResultViewModel(model, dataTable);
        }
예제 #13
0
        public void GivenSortOnFirstColumn_WhenGenerateDataTableResultViewModel_ThenSucceed()
        {
            DataTableRequestModel model = new DataTableRequestModel {
                iDisplayLength = 10
            };
            User userEntity = EducationContext.Users.First(u => u.UserRoles.Select(ur => ur.Role).Any(r => r.Name == SecurityRoles.DataAdmin));
            EducationSecurityPrincipal user        = new EducationSecurityPrincipal(userEntity);
            HttpRequestBase            mockRequest = MockHttpContextFactory.CreateRequest();

            mockRequest.Expect(m => m["iSortCol_0"]).Return("0");
            mockRequest.Expect(m => m["sSortDir_0"]).Return("asc");
            ServiceTypeClientDataTable dataTable = new ServiceTypeClientDataTable(mockRequest, user);

            Target.GenerateDataTableResultViewModel(model, dataTable);
        }
        public void GivenSortOnStatus_WhenGenerateDataTableResultViewModel_ThenViewModelContainsData()
        {
            HttpContextBase       mockHttpContext = MockHttpContextFactory.Create();
            DataTableRequestModel viewModel       = new DataTableRequestModel {
                iDisplayLength = 10
            };

            mockHttpContext.Request.Expect(m => m["iSortCol_0"]).Return("0");
            mockHttpContext.Request.Expect(m => m["sSortDir_0"]).Return("acs");
            UserClientDataTable dataTable = new UserClientDataTable(mockHttpContext.Request, new DefaultSecurityConfiguration());

            DataTableResultModel actual = Target.GenerateDataTableResultViewModel(viewModel, dataTable);

            Assert.AreNotEqual(0, actual.aaData.Count());
        }
예제 #15
0
        public void InitializeTest()
        {
            TestData = new TestData();
            User     = new EducationSecurityPrincipal(new User {
                UserKey = "TestKey"
            });
            MockContext = MockHttpContextFactory.Create();
            MockContext.Expect(m => m.User).Return(User);
            MockBlobClient    = MockRepository.GenerateMock <IBlobClient>();
            MockBlobContainer = MockRepository.GenerateMock <IBlobContainer>();
            MockBlobContainer.Expect(m => m.DownloadToStream(null, null)).IgnoreArguments().Do(new Action <string, Stream>((address, target) =>
            {
                byte[] byteArray = File.ReadAllBytes(address);
                target.Write(byteArray, 0, (int)byteArray.Length);
            }));
            MockBlobContainer.Expect(m => m.UploadFromStream(null, null)).IgnoreArguments().Do(new Action <string, Stream>((address, stream) =>
            {
                File.WriteAllBytes(address, ((MemoryStream)stream).ToArray());
            }));
            MockBlobClient.Expect(m => m.CreateContainer(BaseFileProcessor.ServiceFileContainerName)).IgnoreArguments().Return(MockBlobContainer);
            FileData = new DataTable();
            FileData.Columns.Add("blank", typeof(string));
            FileData.Columns.Add("Id", typeof(string));
            FileData.Columns.Add("DateAttended", typeof(string));
            FileData.Columns.Add("Subject", typeof(string));
            FileData.Columns.Add("Duration", typeof(string));
            FileData.Columns.Add("Notes", typeof(string));
            DataRow row = FileData.NewRow();

            FileData.Rows.Add(row);
            row       = FileData.NewRow();
            row["Id"] = "2";
            FileData.Rows.Add(row);
            row                 = FileData.NewRow();
            row["Id"]           = "STUDENT ID";
            row["DateAttended"] = "DATE";
            row["Subject"]      = "SUBJECT";
            row["Duration"]     = "DURATION";
            row["Notes"]        = "NOTES";
            FileData.Rows.Add(row);
            Repositories = new TestRepositories(TestData);
            IPermissionFactory mockPermissionFactory = MockRepository.GenerateMock <IPermissionFactory>();

            PermissionFactory.SetCurrent(mockPermissionFactory);
            Target = new ServiceAttendanceFileProcessor(MockBlobClient, Repositories.MockRepositoryContainer);
        }
예제 #16
0
        public void InitializeTest()
        {
            EducationContext = new EducationDataContext();
            Container        = AssemblySetup.CreateWindsorContainer(EducationContext);
            RepositoryContainer   repositoryContainer = new RepositoryContainer(Container, EducationContext);
            SchoolDistrictManager logicManager        = new SchoolDistrictManager(repositoryContainer, new DataTableBinder(), new UserAuditor());

            Target = new StudentController(logicManager);
            User userEntity = EducationContext.Users.Include("UserRoles.Role").Include("UserRoles.Schools").Include("UserRoles.Providers").Single(s => s.UserKey == "Bob");

            User            = new EducationSecurityPrincipal(userEntity);
            MockHttpContext = MockHttpContextFactory.Create();
            MockHttpContext.Expect(m => m.User).Return(User);
            ControllerContext context = new ControllerContext(MockHttpContext, new RouteData(), Target);

            Target.ControllerContext = context;
        }
 private static HttpContextBase CreateHttpContextBase(bool mockableContext, string userKey)
 {
     if (mockableContext)
     {
         HttpContextBase httpContext = MockHttpContextFactory.Create();
         httpContext.Expect(m => m.User).Return(MockRepository.GenerateMock <IPrincipal>());
         httpContext.User.Expect(m => m.Identity).Return(MockRepository.GenerateMock <IIdentity>());
         httpContext.User.Identity.Expect(m => m.IsAuthenticated).Return(false);
         httpContext.Request.Expect(m => m.Url).Return(new Uri("http://site.com/Bob/123"));
         httpContext.Request.Expect(m => m.RawUrl).Return("Bob/123");
         httpContext.Request.Headers.Add("Host", "site.com");
         return(httpContext);
     }
     else
     {
         return(new UserHttpContext(userKey));
     }
 }
        public void GivenSort_AndOneServiceAttendanceIsVeryLarge_WhenGenerateDataTableResultViewModel_ThenSucceed()
        {
            DataTableRequestModel model = new DataTableRequestModel();

            model.iDisplayLength = 10;
            var request = MockHttpContextFactory.CreateRequest();

            request.Expect(r => r["id"]).Return("1");
            request.Expect(r => r["iSortCol_0"]).Return("0");
            request.Expect(r => r["sSortDir_0"]).Return("asc");
            ServiceAttendanceClientDataTable dataTable = new ServiceAttendanceClientDataTable(request);
            ServiceAttendance attendance = new ServiceAttendance
            {
                DateAttended            = DateTime.Now.AddYears(100),
                StudentAssignedOffering = EducationContext.StudentAssignedOfferings.Where(s => s.Id == 1).Single(),
                Subject      = EducationContext.Subjects.First(),
                CreatingUser = User.Identity.User
            };

            EducationContext.ServiceAttendances.Add(attendance);
            EducationContext.SaveChanges();

            var actual = Target.GenerateDataTableResultViewModel(model, dataTable);
        }
        public void GivenNullType_WhenICreateController_ThenThrowHttpException()
        {
            RequestContext request = new RequestContext(MockHttpContextFactory.Create(), new RouteData());

            Target.ExpectException <HttpException>(() => Target.ExecuteGetControllerInstance(request, null));
        }
예제 #20
0
 public void InitializeTest()
 {
     MockRequest = MockHttpContextFactory.CreateRequest();
 }
 public void InitializeTest()
 {
     MockHttpContext = MockHttpContextFactory.Create();
     Target          = new HandleEntityErrorAttribute();
 }
예제 #22
0
 public void InitializeTest()
 {
     MockRequest           = MockHttpContextFactory.CreateRequest();
     SecurityConfiguration = MockRepository.GenerateMock <ISecurityConfiguration>();
     TestData = new TestData();
 }
예제 #23
0
        public void GivenUserIsProvider_WhenGenerateDataTableResultViewModel_ThenSucceed()
        {
            DataTableRequestModel model = new DataTableRequestModel {
                iDisplayLength = 10
            };

            User.Identity.User.UserRoles = new List <UserRole>
            {
                new UserRole
                {
                    Role = new Role {
                        Name = SecurityRoles.Provider
                    },
                    Providers = new List <Provider> {
                        EducationContext.Providers.First()
                    }
                }
            };
            ServiceOfferingClientDataTable dataTable = new ServiceOfferingClientDataTable(MockHttpContextFactory.CreateRequest(), User);

            Target.GenerateDataTableResultViewModel(model, dataTable);
        }
예제 #24
0
        public void WhenGenerateDataTableResultViewModel_ThenSucceed()
        {
            DataTableRequestModel model = new DataTableRequestModel {
                iDisplayLength = 10
            };
            ServiceOfferingClientDataTable dataTable = new ServiceOfferingClientDataTable(MockHttpContextFactory.CreateRequest(), User);

            Target.GenerateDataTableResultViewModel(model, dataTable);
        }