public void GetValidatedString_InValidValue_ThrowException()
        {
            CourseDifficultyLevelField courseDifficultyLevelField = RecorderManager.CreateMockedObject <CourseDifficultyLevelField>();
            object value = "-1";

            string returnValue = courseDifficultyLevelField.GetValidatedString(value);
        }
        private SPWeb GetMockSPWeb(bool userFound)
        {
            var web  = RecorderManager.CreateMockedObject <SPWeb>();
            var user = RecorderManager.CreateMockedObject <SPUser>();

            if (!userFound)
            {
                user = null;
            }

            using (RecordExpectations recorder = RecorderManager.StartRecording())
            {
                SPUser spUser = web.SiteUsers.GetByID(12345);
                recorder.Return(user);
            }

            if (user != null)
            {
                using (RecordExpectations recorder = RecorderManager.StartRecording())
                {
                    string userName = user.Name;
                    recorder.Return("MockUserName").RepeatAlways();
                    string userEmail = user.LoginName;
                    recorder.Return("*****@*****.**").RepeatAlways();
                }
            }
            return(web);
        }
        private SPWeb CreateMockSPWeb(bool blank, bool validUser)
        {
            SPWeb web = RecorderManager.CreateMockedObject <SPWeb>();

            if (!blank)
            {
                SPUserCollection users = RecorderManager.CreateMockedObject <SPUserCollection>();

                if (validUser)
                {
                    SPUser user = RecorderManager.CreateMockedObject <SPUser>();

                    using (RecordExpectations recorder = RecorderManager.StartRecording())
                    {
                        recorder.ExpectAndReturn(web.SiteUsers.GetCollection(new string[] { }), users);
                        recorder.ExpectAndReturn(users.Count, 1);
                        recorder.ExpectAndReturn(users[0].LoginName, string.Format(@"{0}\{1}", Environment.MachineName, "spgemployee"));
                        recorder.ExpectAndReturn(users[0], user);
                        recorder.ExpectAndReturn(user.ID, 1).RepeatAlways();
                        recorder.ExpectAndReturn(user.Name, "SPG Employee").RepeatAlways();
                        recorder.ExpectAndReturn(user.LoginName, string.Format(@"{0}\{1}", Environment.MachineName, "spgemployee")).RepeatAlways();
                    }
                }
                else
                {
                    using (RecordExpectations recorder = RecorderManager.StartRecording())
                    {
                        recorder.ExpectAndReturn(web.SiteUsers.GetCollection(new string[] { }), users);
                        recorder.ExpectAndReturn(users.Count, 0);
                    }
                }
            }

            return(web);
        }
        private SPItemEventProperties CreateMockSpItemEventProperties(string title, string code, DateTime enrollmentDate, DateTime startDate, DateTime endDate, float courseCost)
        {
            //Create any mock objects we'll need here
            SPItemEventProperties spItemEventProperties = RecorderManager.CreateMockedObject <SPItemEventProperties>();
            SPWeb web = RecorderManager.CreateMockedObject <SPWeb>();
            SPItemEventDataCollection afterProperties = RecorderManager.CreateMockedObject <SPItemEventDataCollection>();

            //record our main expectations
            using (RecordExpectations recorder = RecorderManager.StartRecording())
            {
                object obj = spItemEventProperties.AfterProperties;
                recorder.Return(afterProperties).RepeatAlways();

                afterProperties["Title"] = string.Empty;
                afterProperties["TrainingCourseCode"] = string.Empty;

                spItemEventProperties.OpenWeb();
                recorder.Return(web);

                obj = spItemEventProperties.ListItem[new Guid(Fields.TrainingCourseCode)];
                recorder.Return("12345678").RepeatAlways();
            }

            //Record our expectations for our AfterProperties collection
            MockHelper.RecordSPItemEventDataCollection(afterProperties, "Title", title);
            MockHelper.RecordSPItemEventDataCollection(afterProperties, "TrainingCourseCode", code);
            MockHelper.RecordSPItemEventDataCollection(afterProperties, "TrainingCourseEnrollmentDate", enrollmentDate);
            MockHelper.RecordSPItemEventDataCollection(afterProperties, "TrainingCourseStartDate", startDate);
            MockHelper.RecordSPItemEventDataCollection(afterProperties, "TrainingCourseEndDate", endDate);
            MockHelper.RecordSPItemEventDataCollection(afterProperties, "TrainingCourseCost", courseCost);

            return(spItemEventProperties);
        }
        private SPWeb RecordWebForUpdate()
        {
            SPWeb  web  = RecorderManager.CreateMockedObject <SPWeb>();
            SPList list = RecorderManager.CreateMockedObject <SPList>();
            SPListItemCollection itemCollection = RecorderManager.CreateMockedObject <SPListItemCollection>();
            SPListItem           item           = RecorderManager.CreateMockedObject <SPListItem>();

            using (RecordExpectations recorder = RecorderManager.StartRecording())
            {
                recorder.ExpectAndReturn(web.Lists["Registrations"], list).RepeatAlways();
                recorder.ExpectAndReturn(list.GetItems(new SPQuery()), itemCollection).RepeatAlways();
                recorder.ExpectAndReturn(itemCollection.Count, 1);
                recorder.ExpectAndReturn(itemCollection[0], item);
                item[new Guid(Fields.CourseId)] = 1;
                recorder.CheckArguments();
                item[new Guid(Fields.UserId)] = 1;
                recorder.CheckArguments();
                //recorder.ExpectAndReturn(web.AllowUnsafeUpdates, false);
                //web.AllowUnsafeUpdates = true;
                item.Update();
                //web.AllowUnsafeUpdates = false;
            }

            return(web);
        }
        private SPListItem CreateMockSPListItem(SPListItemMockType mockType, string status)
        {
            SPListItem listItem = RecorderManager.CreateMockedObject <SPListItem>();

            switch (mockType)
            {
            case SPListItemMockType.Populate:
                using (RecordExpectations recorder = RecorderManager.StartRecording())
                {
                    recorder.ExpectAndReturn(listItem.ID, 1);
                }
                break;

            case SPListItemMockType.StatusCheck:
                using (RecordExpectations recorder = RecorderManager.StartRecording())
                {
                    recorder.ExpectAndReturn(listItem[new Guid(Fields.RegistrationStatus)], status);
                }
                break;

            default:
                using (RecordExpectations recorder = RecorderManager.StartRecording())
                {
                    recorder.ExpectAndReturn(listItem.ID, 1);
                }
                break;
            }

            return(listItem);
        }
Пример #7
0
 public static void SPContextWeb()
 {
     using (RecordExpectations rec = new RecordExpectations())
     {
         SPWeb web = RecorderManager.CreateMockedObject <SPWeb>(Constructor.Mocked);
         rec.ExpectAndReturn(SPContext.Current.Web, web).RepeatAlways();
     }
 }
        public void GetValidatedString_ValidValue_ReturnValue()
        {
            CourseDifficultyLevelField courseDifficultyLevelField = RecorderManager.CreateMockedObject <CourseDifficultyLevelField>();
            object value = "1";

            string returnValue = courseDifficultyLevelField.GetValidatedString(value);

            Assert.AreEqual("1", returnValue);
        }
Пример #9
0
        private SPWeb RecordGetFieldName()
        {
            SPWeb web = RecorderManager.CreateMockedObject <SPWeb>();

            using (RecordExpectations recorder = RecorderManager.StartRecording())
            {
                recorder.ExpectAndReturn(web.Lists[""].Fields[new Guid()].InternalName, "UnitTestField");
            }

            return(web);
        }
        private SPListItem RecordAddSPListItem()
        {
            SPListItem item = RecorderManager.CreateMockedObject <SPListItem>();

            using (RecordExpectations recorder = RecorderManager.StartRecording())
            {
                recorder.ExpectAndReturn(item[new Guid(Fields.Id)], 1);
            }

            return(item);
        }
        private SPWeb RecordUpdateReturnSPWeb()
        {
            SPWeb  web  = RecorderManager.CreateMockedObject <SPWeb>();
            SPUser user = RecorderManager.CreateMockedObject <SPUser>();

            using (RecordExpectations recorder = RecorderManager.StartRecording())
            {
                recorder.ExpectAndReturn(web.SiteUsers.GetByID(1), user);
            }

            return(web);
        }
        public void CanDelete()
        {
            SPWeb web = RecorderManager.CreateMockedObject <SPWeb>();

            serviceLocator.Register <IListItemRepository>(typeof(MockListItemRepository));
            RegistrationRepository repository = new RegistrationRepository();

            repository.Delete(1, web);

            Assert.IsTrue(MockListItemRepository.CalledUpdateOrDelete);
            MockManager.Verify();
        }
Пример #13
0
        private SPListItem RecordGetReturnSPListItem()
        {
            SPListItem item = RecorderManager.CreateMockedObject <SPListItem>();

            using (RecordExpectations recorder = RecorderManager.StartRecording())
            {
                recorder.ExpectAndReturn(item[new Guid(Fields.Id)], 1);
                recorder.ExpectAndReturn(item[new Guid(Fields.Title)], "TestTitle");
                recorder.ExpectAndReturn(item[new Guid(Fields.WorkflowItemId)], 5);
            }

            return(item);
        }
        private SPWeb RecordWebForGetAll()
        {
            SPWeb  web  = RecorderManager.CreateMockedObject <SPWeb>();
            SPList list = RecorderManager.CreateMockedObject <SPList>();
            SPListItemCollection itemCollection = RecorderManager.CreateMockedObject <SPListItemCollection>();

            using (RecordExpectations recorder = RecorderManager.StartRecording())
            {
                recorder.ExpectAndReturn(web.Lists["Registrations"], list).RepeatAlways();
                recorder.ExpectAndReturn(list.Items, itemCollection).RepeatAlways();
                recorder.ExpectAndReturn(itemCollection.Count, 2);
            }

            return(web);
        }
        private SPListItem RecordGetReturnSPListItem()
        {
            SPListItem item = RecorderManager.CreateMockedObject <SPListItem>();

            using (RecordExpectations recorder = RecorderManager.StartRecording())
            {
                recorder.ExpectAndReturn(item[new Guid(Fields.Id)], 1);
                recorder.ExpectAndReturn(item[new Guid(Fields.Title)], "UNITTEST");
                recorder.ExpectAndReturn(item[new Guid(Fields.CourseId)], 1);
                recorder.ExpectAndReturn(item[new Guid(Fields.UserId)], 1);
                recorder.ExpectAndReturn(item[new Guid(Fields.RegistrationStatus)], "Pending");
            }

            return(item);
        }
Пример #16
0
        public void CanUpdate()
        {
            SPWeb web = RecorderManager.CreateMockedObject <SPWeb>();
            RegistrationApprovalTask registrationApprovalTask = new RegistrationApprovalTask();

            registrationApprovalTask.Id             = 1;
            registrationApprovalTask.Title          = "TestTitle";
            registrationApprovalTask.WorkflowItemId = 5;
            serviceLocator.Register <IListItemRepository>(typeof(MockListItemRepository));
            RegistrationApprovalTaskRepository registrationApprovalTaskRepository = new RegistrationApprovalTaskRepository();

            registrationApprovalTaskRepository.Update(registrationApprovalTask, web);

            Assert.IsTrue(MockListItemRepository.CalledUpdateOrDelete);
            MockManager.Verify();
        }
Пример #17
0
        public void CanAdd()
        {
            SPWeb      web  = RecorderManager.CreateMockedObject <SPWeb>();
            SPListItem item = this.RecordAddSPListItem();
            RegistrationApprovalTask registrationApprovalTask = new RegistrationApprovalTask();

            registrationApprovalTask.Title                 = "TestTitle";
            registrationApprovalTask.WorkflowItemId        = 5;
            MockListItemRepository.SPListItemReturnedByGet = item;
            serviceLocator.Register <IListItemRepository>(typeof(MockListItemRepository));
            RegistrationApprovalTaskRepository registrationApprovalTaskRepository = new RegistrationApprovalTaskRepository();

            int id = registrationApprovalTaskRepository.Add(registrationApprovalTask, web);

            Assert.AreEqual(1, id);
            MockManager.Verify();
        }
Пример #18
0
        public void CanGetById()
        {
            SPWeb      web  = RecorderManager.CreateMockedObject <SPWeb>();
            SPListItem item = this.RecordGetReturnSPListItem();
            RegistrationApprovalTask registrationApprovalTask = new RegistrationApprovalTask();

            MockListItemRepository.SPListItemReturnedByGet = item;
            serviceLocator.Register <IListItemRepository>(typeof(MockListItemRepository));
            RegistrationApprovalTaskRepository registrationApprovalTaskRepository = new RegistrationApprovalTaskRepository();

            registrationApprovalTask = registrationApprovalTaskRepository.Get(1, web);

            Assert.IsNotNull(registrationApprovalTask);
            Assert.AreEqual <int>(1, registrationApprovalTask.Id);
            Assert.AreEqual <string>("TestTitle", registrationApprovalTask.Title);
            Assert.AreEqual <int>(5, registrationApprovalTask.WorkflowItemId);
            MockManager.Verify();
        }
Пример #19
0
        private SPListItem RecordGetReturnSPListItem()
        {
            SPListItem item = RecorderManager.CreateMockedObject <SPListItem>();

            using (RecordExpectations recorder = RecorderManager.StartRecording())
            {
                recorder.ExpectAndReturn(item[new Guid(Fields.Id)], 1);
                recorder.ExpectAndReturn(item[new Guid(Fields.Title)], "TestTitle");
                recorder.ExpectAndReturn(item[new Guid(Fields.TrainingCourseCode)], "TestCode");
                recorder.ExpectAndReturn(item[new Guid(Fields.TrainingCourseDescription)], "TestDescription");
                recorder.ExpectAndReturn(item[new Guid(Fields.TrainingCourseEnrollmentDate)], DateTime.Today);
                recorder.ExpectAndReturn(item[new Guid(Fields.TrainingCourseStartDate)], DateTime.Today.AddDays(1));
                recorder.ExpectAndReturn(item[new Guid(Fields.TrainingCourseEndDate)], DateTime.Today.AddDays(2));
                recorder.ExpectAndReturn(item[new Guid(Fields.TrainingCourseCost)], 123f);
            }

            return(item);
        }
        private SPWeb CreateMockSPWeb(SPWebMockType mockType)
        {
            SPWeb  web     = RecorderManager.CreateMockedObject <SPWeb>();
            SPUser user    = RecorderManager.CreateMockedObject <SPUser>();
            SPUser manager = RecorderManager.CreateMockedObject <SPUser>();

            switch (mockType)
            {
            case SPWebMockType.UserAndManager:
                using (RecordExpectations recorder = RecorderManager.StartRecording())
                {
                    recorder.ExpectAndReturn(web.SiteUsers.GetByID(1), user);
                    recorder.ExpectAndReturn(user.LoginName, @"domain\alias").RepeatAlways();
                    recorder.ExpectAndReturn(web.SiteUsers[1], manager);
                    recorder.ExpectAndReturn(manager.LoginName, string.Format(@"{0}\{1}", Environment.MachineName, "spgmanager"));
                    recorder.ExpectAndReturn(user.Name, "TestUser").RepeatAlways();
                }
                break;

            case SPWebMockType.UserOnly:
                using (RecordExpectations recorder = RecorderManager.StartRecording())
                {
                    recorder.ExpectAndReturn(web.SiteUsers.GetByID(1), user);
                    recorder.ExpectAndReturn(user.LoginName, @"domain\alias").RepeatAlways();
                    recorder.ExpectAndReturn(user.Name, "TestUser").RepeatAlways();
                }
                break;

            default:
                using (RecordExpectations recorder = RecorderManager.StartRecording())
                {
                    recorder.ExpectAndReturn(web.SiteUsers.GetByID(1), user);
                    recorder.ExpectAndReturn(user.LoginName, @"domain\alias").RepeatAlways();
                    recorder.ExpectAndReturn(web.SiteUsers[1], manager);
                    recorder.ExpectAndReturn(manager.LoginName, string.Format(@"{0}\{1}", Environment.MachineName, "spgmanager"));
                    recorder.ExpectAndReturn(user.Name, "TestUser").RepeatAlways();
                }
                break;
            }

            return(web);
        }
        public void CanGetByCourseIdUserId()
        {
            SPWeb        web          = RecorderManager.CreateMockedObject <SPWeb>();
            SPListItem   item         = this.RecordGetReturnSPListItem();
            Registration registration = new Registration();

            MockListItemRepository.SPListItemReturnedByGet = item;
            serviceLocator.Register <IListItemRepository>(typeof(MockListItemRepository));
            RegistrationRepository repository = new RegistrationRepository();

            registration = repository.Get(1, 1, web);

            Assert.IsNotNull(registration);
            Assert.AreEqual <int>(1, registration.Id);
            Assert.AreEqual <string>("UNITTEST", registration.Title);
            Assert.AreEqual <int>(1, registration.CourseId);
            Assert.AreEqual <int>(1, registration.UserId);
            Assert.AreEqual <string>("Pending", registration.RegistrationStatus);
            MockManager.Verify();
        }
Пример #22
0
        public void CanUpdate()
        {
            SPWeb          web    = RecorderManager.CreateMockedObject <SPWeb>();
            TrainingCourse course = new TrainingCourse();

            course.Id             = 1;
            course.Title          = "TestTitle";
            course.Code           = "TestCode";
            course.Description    = "TestDescription";
            course.EnrollmentDate = DateTime.Today;
            course.StartDate      = DateTime.Today.AddDays(1);
            course.EndDate        = DateTime.Today.AddDays(2);
            course.Cost           = 123f;
            serviceLocator.Register <IListItemRepository>(typeof(MockListItemRepository));
            TrainingCourseRepository repository = new TrainingCourseRepository();

            repository.Update(course, web);

            Assert.IsTrue(MockListItemRepository.CalledUpdateOrDelete);
            MockManager.Verify();
        }
Пример #23
0
        public void CanAdd()
        {
            SPWeb          web    = RecorderManager.CreateMockedObject <SPWeb>();
            SPListItem     item   = this.RecordAddSPListItem();
            TrainingCourse course = new TrainingCourse();

            course.Title          = "TestTitle";
            course.Code           = "TestCode";
            course.Description    = "TestDescription";
            course.EnrollmentDate = DateTime.Today;
            course.StartDate      = DateTime.Today.AddDays(1);
            course.EndDate        = DateTime.Today.AddDays(2);
            course.Cost           = 123f;
            MockListItemRepository.SPListItemReturnedByGet = item;
            serviceLocator.Register <IListItemRepository>(typeof(MockListItemRepository));
            TrainingCourseRepository repository = new TrainingCourseRepository();

            int id = repository.Add(course, web);

            Assert.AreEqual(1, id);
            MockManager.Verify();
        }
Пример #24
0
        public void CanGetById()
        {
            SPWeb          web    = RecorderManager.CreateMockedObject <SPWeb>();
            SPListItem     item   = this.RecordGetReturnSPListItem();
            TrainingCourse course = new TrainingCourse();

            MockListItemRepository.SPListItemReturnedByGet = item;
            serviceLocator.Register <IListItemRepository>(typeof(MockListItemRepository));
            TrainingCourseRepository repository = new TrainingCourseRepository();

            course = repository.Get(1, web);

            Assert.IsNotNull(course);
            Assert.AreEqual <int>(1, course.Id);
            Assert.AreEqual <string>("TestTitle", course.Title);
            Assert.AreEqual <string>("TestCode", course.Code);
            Assert.AreEqual <string>("TestDescription", course.Description);
            Assert.AreEqual <DateTime>(DateTime.Today, course.EnrollmentDate);
            Assert.AreEqual <DateTime>(DateTime.Today.AddDays(1), course.StartDate);
            Assert.AreEqual <DateTime>(DateTime.Today.AddDays(2), course.EndDate);
            Assert.AreEqual <float>(123f, course.Cost);
            MockManager.Verify();
        }
Пример #25
0
        private SPWeb CreateMockSPWeb(bool blank)
        {
            SPWeb web = RecorderManager.CreateMockedObject <SPWeb>();

            using (RecordExpectations recorder = RecorderManager.StartRecording())
            {
                recorder.ExpectAndReturn(web.Url, "http://localhost/training");
            }

            if (!blank)
            {
                SPUser user = RecorderManager.CreateMockedObject <SPUser>();

                using (RecordExpectations recorder = RecorderManager.StartRecording())
                {
                    recorder.ExpectAndReturn(web.SiteUsers[string.Empty], user);
                    recorder.ExpectAndReturn(user.Name, @"domain\alias").RepeatAlways();
                    recorder.ExpectAndReturn(user.ID, 1).RepeatAlways();
                }
            }

            return(web);
        }