Beispiel #1
0
        public void Can_Set_Document_As_Not_Visible_To_Members()
        {
            // Setup
            IProcess <OrgMemberDocVisibilityByOrgAdminParams, GeneralSuccessResultViewModel> process = new OrganizationDocumentProcesses(_context);

            var org  = new Organization();
            var user = new User {
                Organization = org, IsOrganizationAdmin = true
            };
            var doc = new OfficialDocument {
                MeantForMembers = true
            };

            org.MemberOfficialDocuments.Add(doc);

            _context.Organizations.Add(org);
            _context.Users.Add(user);
            _context.OfficialDocuments.Add(doc);
            _context.SaveChanges();

            // Act
            var result = process.Execute(new OrgMemberDocVisibilityByOrgAdminParams
            {
                OfficialDocumentId = doc.Id,
                RequestingUserId   = user.Id,
                ShowToMembers      = false
            });

            // Verify
            Assert.IsNotNull(result, "Process returned a null result");
            Assert.IsTrue(result.WasSuccessful, "Process did not return a successful result");
            Assert.AreEqual(0, org.MemberOfficialDocuments.Count, "Organization had an incorrect number of member documents");
        }
        public void Returns_Empty_List_When_User_Id_Not_Found()
        {
            // Setup
            IProcess <ByUserIdParams, VisibleOrgOfficialDocListForUserViewModel> process =
                new OrganizationDocumentProcesses(_context);

            // Act
            VisibleOrgOfficialDocListForUserViewModel result = process.Execute(new ByUserIdParams {
                UserId = 0
            });

            // Verify
            Assert.IsNotNull(result, "Process result is null");
            Assert.AreEqual(0, result.UserVisibleDocuments.Count, "Document list contained an incorrect number of elements");
        }
Beispiel #3
0
        public void Throws_Exception_When_User_Not_Organization_Admin()
        {
            // Setup
            IProcess <OrgMemberDocVisibilityByOrgAdminParams, GeneralSuccessResultViewModel> process = new OrganizationDocumentProcesses(_context);

            var org  = new Organization();
            var user = new User {
                Organization = org, IsOrganizationAdmin = false
            };
            var doc = new OfficialDocument {
                MeantForMembers = true
            };

            org.MemberOfficialDocuments.Add(doc);

            _context.Users.Add(user);
            _context.OfficialDocuments.Add(doc);
            _context.SaveChanges();

            // Act
            try
            {
                process.Execute(new OrgMemberDocVisibilityByOrgAdminParams
                {
                    OfficialDocumentId = doc.Id,
                    RequestingUserId   = user.Id,
                    ShowToMembers      = false
                });
                Assert.Fail("No exception was thrown");
            }

            // Verify
            catch (UserNotAuthorizedForEntityException ex)
            {
                Assert.AreEqual(user.Id, ex.UserId, "Exception's user id value was not correct");
                Assert.AreEqual(user.Organization.Id, ex.IdValue, "Exception's entity id value was not correct");
                Assert.AreEqual(typeof(Organization), ex.EntityType, "Exception's entity type value was not correct");
            }
        }
        public void Can_Get_List_Of_Documents_Visible_To_User()
        {
            // Setup
            var doc1 = new OfficialDocument {
                MeantForMembers = true
            };
            var doc2 = new OfficialDocument {
                MeantForMembers = true
            };
            var doc3 = new OfficialDocument {
                MeantForMembers = true
            };
            var org  = new Organization();
            var user = new User {
                Organization = org
            };

            org.MemberOfficialDocuments.Add(doc1);
            org.MemberOfficialDocuments.Add(doc3);
            _context.Users.Add(user);
            _context.SaveChanges();

            IProcess <ByUserIdParams, VisibleOrgOfficialDocListForUserViewModel> process =
                new OrganizationDocumentProcesses(_context);

            // Act
            VisibleOrgOfficialDocListForUserViewModel result = process.Execute(new ByUserIdParams {
                UserId = user.Id
            });

            // Verify
            Assert.IsNotNull(result, "Process result is null");
            Assert.AreEqual(2, result.UserVisibleDocuments.Count, "Document list contained an incorrect number of elements");
            Assert.IsTrue(result.UserVisibleDocuments.Contains(doc1), "Document list did not contain doc1");
            Assert.IsTrue(result.UserVisibleDocuments.Contains(doc3), "Document list did not contain doc3");
        }