コード例 #1
0
        public void FindUserListItemModelTest()
        {
            // Warning: This test can fail if another test is creating users at the same time
            //          This occurs because users are global and not specific to an organisation,
            //          otherwise we segment users off into a separate test organisation.
            var user        = GetTestUser();
            var testCompany = GetTestCompany(user);
            var model       = MembershipManagementService.FindUserListItemModel();
            var dbData      = db.FindUsers();

            int expected = dbData.Count(),
                actual   = model.Count();

            Assert.IsTrue(actual == expected, $"Error: {actual} items were found when {expected} were expected");

            // Check that all the items match
            foreach (var item in model)
            {
                var dbItem = dbData.Where(m => m.Id.ToString() == item.Id).FirstOrDefault();
                Assert.IsTrue(dbItem != null, "Error: Model item not found in db item list");

                var test = MembershipManagementService.MapToModel(dbItem);
                AreEqual(item, test);
            }

            // Add another item a make sure it is found
            var newItem = GetTestUser(true, false);
            var error   = MembershipManagementService.InsertOrUpdateUser(newItem, user, "");

            Assert.IsTrue(!error.IsError, $"Error: {error.Message}");

            model = MembershipManagementService.FindUserListItemModel();
            var testItem = model.Where(i => i.Id.ToString() == newItem.Id.ToString()).FirstOrDefault();

            Assert.IsTrue(testItem != null, "Error: A NULL value was returned when a non-NULL value was expected");

            // Delete it and make sure it disappears
            MembershipManagementService.DeleteUser(newItem.Id);

            model    = MembershipManagementService.FindUserListItemModel();
            testItem = model.Where(i => i.Id == newItem.Id.ToString()).FirstOrDefault();
            Assert.IsTrue(testItem == null, "Error: A non-NULL value was returned when a NULL value was expected");
        }
コード例 #2
0
        public void DeleteUserTest()
        {
            var testUser = GetTestUser();

            var dbUser = db.FindUser(testUser.Id);

            Assert.IsTrue(dbUser != null, "Error: A NULL value was returned when a non-NULL value was expected (user not found)");

            var checkUser = MembershipManagementService.FindUserModel(dbUser.Id);

            Assert.IsTrue(checkUser != null, "Error: A NULL value was returned when a non-NULL value was expected (user not found)");

            var dbUserModel = MembershipManagementService.MapToModel(dbUser);

            AreEqual(checkUser, dbUserModel);

            MembershipManagementService.DeleteUser(dbUser.Id);
            checkUser = MembershipManagementService.FindUserModel(dbUser.Id);
            Assert.IsTrue(checkUser == null, "Error: A non-NULL value was returned when a NULL value was expected (user not deleted)");
        }