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);
        }
        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 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);
        }
        public void TestPersistWithNaturalMocking()
        {
            MockManager.Init();

            //Create User
            User user = new User();

            // Natural mocking
            using(RecordExpectations recorder = new RecordExpectations())
            {
                IUserGateway mockGateway = new UserGateway();
                IUserValidator mockValidator = new UserValidator();

                //Expectations
                recorder.ExpectAndReturn(mockValidator.Validate(user), true);
                recorder.ExpectAndReturn(mockGateway.Persist(user), true);
            }

            //Create instances
            IUserGateway gateway = new UserGateway();
            IUserValidator validator = new UserValidator();

            //Assign gateway
            user.Gateway = gateway;

            //Test method
            Assert.AreEqual(true, user.Persist(validator));

            MockManager.Verify();
        }
        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 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);
        }
Ejemplo n.º 7
0
        public void GetCalendarDate_FromCache()
        {
            CalendarDate cDate = new CalendarDate();
            cDate.Date = DateTime.Now;
            cDate.WorkRate = TimeSpan.FromHours(6);

            using (RecordExpectations recorder = new RecordExpectations())
            {
                Cache.Contains(null);
                recorder.Return(true);

                Cache.InsertDate(null);
                recorder.Return(DateTime.Now);

                Cache.GetObject(null);
                recorder.Return(cDate);

                Cache.Add(null, null);
            }

            ICalendarDate icDate = UlterSystems.PortalLib.BusinessObjects.Calendar.GetCalendarDate(DateTime.Now);
            Assert.AreSame(cDate, icDate);
            Assert.AreEqual(DateTime.Today, icDate.Date);
            Assert.AreEqual(TimeSpan.FromHours(6), icDate.WorkRate);
            Assert.IsFalse(icDate.IsHoliday);
        }
Ejemplo n.º 8
0
 public static void SPContextWeb()
 {
     using (RecordExpectations rec = new RecordExpectations())
     {
         SPWeb web = RecorderManager.CreateMockedObject <SPWeb>(Constructor.Mocked);
         rec.ExpectAndReturn(SPContext.Current.Web, web).RepeatAlways();
     }
 }
Ejemplo n.º 9
0
 /// <summary>
 /// RecordSPItemEventDataCollection mocks the Get behavior of the
 /// SPItemEventDataCollection collection.
 /// </summary>
 /// <param name="properties">A mocked instance of an SPItemEventDataCollection object</param>
 /// <param name="fieldName">the name of the SPField that will be used as the indexer</param>
 /// <param name="value">the mocked value to return</param>
 public static void RecordSPItemEventDataCollection(SPItemEventDataCollection properties, string fieldName, object value)
 {
     using (RecordExpectations recorder = RecorderManager.StartRecording())
     {
         object val = properties[fieldName];
         recorder.Return(value).RepeatAlways().WhenArgumentsMatch();
     }
 }
Ejemplo n.º 10
0
 /// <summary>
 /// The RecordFieldInternalName method will mock the Get of the InternalName property
 /// of an SPField
 /// </summary>
 /// <param name="list">a mocked SPList object</param>
 /// <param name="id">the unique identifier of the SPField</param>
 /// <param name="internalName">the mocked InternalName</param>
 internal static void RecordFieldInternalName(SPList list, Guid id, string internalName)
 {
     using (RecordExpectations recorder = RecorderManager.StartRecording())
     {
         SPField field = list.Fields[id];
         recorder.CheckArguments();
         string fieldName = field.InternalName;
         recorder.Return(internalName).RepeatAlways();
     }
 }
        private SPListItem RecordAddSPListItem()
        {
            SPListItem item = RecorderManager.CreateMockedObject <SPListItem>();

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

            return(item);
        }
Ejemplo n.º 12
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 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);
        }
Ejemplo n.º 14
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);
        }
Ejemplo n.º 17
0
        public void GetCalendarDate_NotFromCache()
        {
            using (RecordExpectations recorder = new RecordExpectations())
            {
                Cache.Contains(null);
                recorder.Return(false);

                DBManager.GetCalendarDate(DateTime.Today);
                recorder.Return(null);

                Cache.Add(null, null);
            }

            ICalendarDate icDate = UlterSystems.PortalLib.BusinessObjects.Calendar.GetCalendarDate(new DateTime(2007, 9, 12));
            Assert.AreEqual(new DateTime(2007, 9, 12), icDate.Date);
            Assert.AreEqual(TimeSpan.FromHours(8), icDate.WorkRate);
            Assert.IsFalse(icDate.IsHoliday);
        }
Ejemplo n.º 18
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);
        }
Ejemplo n.º 20
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);
        }
Ejemplo n.º 21
0
        public void IsHoliday_True()
        {
            CalendarDate cDate = new CalendarDate();
            cDate.WorkRate = TimeSpan.Zero;

            using (RecordExpectations recorder = new RecordExpectations())
            {
                UlterSystems.PortalLib.BusinessObjects.Calendar.GetCalendarDate(DateTime.Now);
                recorder.Return(cDate);
            }

            Assert.IsTrue(UlterSystems.PortalLib.BusinessObjects.Calendar.IsHoliday(DateTime.Now));
        }
Ejemplo n.º 22
0
        public void GetWorkRate()
        {
            CalendarDate cDate = new CalendarDate();
            cDate.WorkRate = TimeSpan.FromHours(3);

            using (RecordExpectations recorder = new RecordExpectations())
            {
                UlterSystems.PortalLib.BusinessObjects.Calendar.GetCalendarDate(DateTime.Now);
                recorder.Return(cDate);
            }

            Assert.AreEqual(TimeSpan.FromHours(3), UlterSystems.PortalLib.BusinessObjects.Calendar.GetWorkRate(DateTime.Now));
        }