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 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);
        }
        public void ScenarioPlayTest()
        {
            using (RecorderManager.NewRecordingSession("test"))
            {
                // Make a callee, not really used but needed to record a constructor call:
                MockingProxy callee = new MockingProxy(typeof(Sample.Account), null, "m1");

                // Push some calls in the recorder:
                MockableCall lastcall;
                CurrentRecorder.RecordCall(lastcall = new MockableCall(callee, typeof(Sample.Account).GetConstructor(new Type[] { typeof(Sample.CurrencyUnit) }), null));
                lastcall.SetConstructionResult("acc");
                CurrentRecorder.RecordCall(lastcall = new MockableCall(callee, typeof(Sample.Account).GetMethod("Deposit"), null));
                lastcall.SetCallResult();
                CurrentRecorder.RecordCall(lastcall = new MockableCall(callee, typeof(Sample.Account).GetMethod("Withdraw"), null));
                lastcall.SetCallResult();
                CurrentRecorder.RecordCall(lastcall = new MockableCall(callee, typeof(Sample.Account).GetProperty("Balance").GetGetMethod(), null));
                lastcall.SetCallResult(10m);
            }

            using (RecorderManager.NewPlayBackSession("test", true))
            {
                // Register types to mock:
                MockService.AddTypeToMock(typeof(Sample.Account));

                // Play scenario:
                Sample.Account acc = new Sample.Account(Sample.CurrencyUnit.EUR);
                acc.Deposit(100m);
                acc.Withdraw(25m);
                Decimal balance = acc.Balance;

                // Checks:
                Assert.AreEqual(10m, balance);                 // Does not match the scenario, but the mocking result !
            }
        }
Esempio n. 5
0
 public void RecordingBeginEnd00Test()
 {
     RecorderManager.BeginRecording("test");
     Assert.IsTrue(RecorderManager.IsRecording);
     RecorderManager.EndRecording();
     Assert.IsFalse(RecorderManager.IsRecording);
 }
Esempio n. 6
0
        public void Activate <T>(T controller, HandleInfo handleInfo) where T : ViewController
        {
            View        view                 = controller.View;
            MockedEvent controlsCreated      = null;
            MockedEvent currentObjectChanged = null;

            if (handleInfo != null)
            {
                if (handleInfo.ControlsCreated)
                {
                    using (RecorderManager.StartRecording()) {
                        view.ControlsCreated += null;
                    }
                    controlsCreated = RecorderManager.LastMockedEvent;
                }
                if (handleInfo.CurrentObjectChanged)
                {
                    using (RecorderManager.StartRecording()) {
                        view.CurrentObjectChanged += null;
                    }
                    currentObjectChanged = RecorderManager.LastMockedEvent;
                }
            }
            controller.Active.Clear();
            controller.Active[""] = true;
            if (controlsCreated != null)
            {
                controlsCreatedHandler = (EventHandler)controlsCreated.GetEventHandle();
            }
            if (currentObjectChanged != null)
            {
                currentObjectChangedHandler = (EventHandler)currentObjectChanged.GetEventHandle();
            }
        }
        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);
        }
 public void LocalPattern02Test()
 {
     using (RecorderManager.NewPlayBackSession("test", false))
     {
         RemotingMockService.AddGlobalMockingUri("*");
     }
 }
        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);
        }
Esempio n. 10
0
 public void MockOutArgsTest()
 {
     using (RecorderManager.NewRecordingSession("test"))
     {
         Assert.AreEqual(RecorderState.Recording, RecorderManager.Action);
         // Scenario:
         Sample.FooBar fb = new Sample.FooBar();
         int           a = 1, b = 2, c, d = 4;
         object        result = fb.SomeMethodWithInsAndOuts(a, ref b, out c, d);
         // Check results:
         Assert.IsNotNull(result);
         Assert.AreEqual(3, b);
         Assert.AreEqual(7, c);
         // Check mocking records:
         Assert.IsTrue(CurrentRecorder[0].IsConstructorCall);
         Assert.IsFalse(CurrentRecorder[1].IsConstructorCall);
         Assert.IsTrue(CurrentRecorder[1].InArgs.Length == 3);
         Assert.AreEqual(1, CurrentRecorder[1].InArgs[0]);
         Assert.AreEqual(2, CurrentRecorder[1].InArgs[1]);
         Assert.AreEqual(4, CurrentRecorder[1].InArgs[2]);
         Assert.IsTrue(CurrentRecorder[1].OutArgs.Length == 2);
         Assert.AreEqual(3, CurrentRecorder[1].OutArgs[0]);
         Assert.AreEqual(7, CurrentRecorder[1].OutArgs[1]);
         Assert.AreEqual(result, CurrentRecorder[1].ReturnValue);
         Assert.AreEqual(1, CurrentRecorder[1].Args[0]);
         Assert.AreEqual(3, CurrentRecorder[1].Args[1]);
         Assert.AreEqual(7, CurrentRecorder[1].Args[2]);
         Assert.AreEqual(4, CurrentRecorder[1].Args[3]);
     }
 }
        public void GetValidatedString_InValidValue_ThrowException()
        {
            CourseDifficultyLevelField courseDifficultyLevelField = RecorderManager.CreateMockedObject <CourseDifficultyLevelField>();
            object value = "-1";

            string returnValue = courseDifficultyLevelField.GetValidatedString(value);
        }
        /// <summary>
        /// Process synchronous messages through the sink chain. Mocking can be applied here.
        /// </summary>
        public IMessage SyncProcessMessage(IMessage msg)
        {
            IMethodCallMessage   mcm = (IMethodCallMessage)msg;
            IMethodReturnMessage result;

            if (RecorderManager.IsPlaying && RemotingMockService.IsUriToMock(mcm.Uri))
            {
                MockingProxy proxy = new MockingProxy(Type.GetType(mcm.TypeName), new RemotingPlayBackMocker(), mcm.Uri);
                result = (IMethodReturnMessage)proxy.Invoke(msg);
            }
            else if (RecorderManager.IsRecording && !RecorderManager.IsInCall && RemotingMockService.IsUriToMock(mcm.Uri))
            {
                MockingProxy proxy = new MockingProxy(Type.GetType(mcm.TypeName), null, mcm.Uri);
                MockableCall call  = new MockableCall(proxy, mcm);
                using (new RecorderManager.Lock()) {
                    result = SyncProcessMessageOnServer(mcm);
                    call.SetResult(result);
                    RecorderManager.RecordCall(call);
                }
            }
            else
            {
                result = (IMethodReturnMessage)nextMessageSink.SyncProcessMessage(msg);
            }
            return(result);
        }
Esempio n. 13
0
 public void PlayBackBeginEnd00Test()
 {
     Assert.IsFalse(RecorderManager.IsPlaying);
     RecorderManager.BeginPlayBack("test");
     Assert.IsTrue(RecorderManager.IsPlaying);
     RecorderManager.EndPlayBack();
     Assert.IsFalse(RecorderManager.IsPlaying);
 }
Esempio n. 14
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();
     }
 }
 public void NoMockingTest()
 {
     using (RecorderManager.NewPlayBackSession("test", false))
     {
         Sample.ICurrencyService srv = Sample.CurrencyServiceFactory.NextInstance;
         Assert.IsFalse(MockService.IsMock(srv));
     }
 }
Esempio n. 16
0
 public static void SPContextWeb()
 {
     using (RecordExpectations rec = new RecordExpectations())
     {
         SPWeb web = RecorderManager.CreateMockedObject <SPWeb>(Constructor.Mocked);
         rec.ExpectAndReturn(SPContext.Current.Web, web).RepeatAlways();
     }
 }
Esempio n. 17
0
 public void AddTypeToMockTest()
 {
     using (RecorderManager.NewPlayBackSession("test", false))
     {
         Assert.IsFalse(MockService.IsTypeToMock(typeof(Sample.CustomizableCurrencyService)));
         MockService.AddTypeToMock(typeof(Sample.CustomizableCurrencyService));
         Assert.IsTrue(MockService.IsTypeToMock(typeof(Sample.CustomizableCurrencyService)));
     }
 }
 public void MockingTest()
 {
     using (RecorderManager.NewPlayBackSession("test", false))
     {
         MockService.AddTypeToMock(typeof(Sample.CustomizableCurrencyService));
         Sample.ICurrencyService srv = Sample.CurrencyServiceFactory.NextInstance;
         Assert.IsTrue(MockService.IsMock(srv));
     }
 }
        public void GetValidatedString_ValidValue_ReturnValue()
        {
            CourseDifficultyLevelField courseDifficultyLevelField = RecorderManager.CreateMockedObject <CourseDifficultyLevelField>();
            object value = "1";

            string returnValue = courseDifficultyLevelField.GetValidatedString(value);

            Assert.AreEqual("1", returnValue);
        }
 public void LocalPattern00Test()
 {
     Assert.IsFalse(RemotingMockService.IsUriToMock("http://localhost/service.rem"));
     using (RecorderManager.NewPlayBackSession("test", false))
     {
         RemotingMockService.AddMockingUri("*");
         Assert.IsTrue(RemotingMockService.IsUriToMock("http://localhost/service.rem"));
     }
     Assert.IsFalse(RemotingMockService.IsUriToMock("http://localhost/service.rem"));
 }
 public void UriPatternsTest()
 {
     using (RecorderManager.NewPlayBackSession("test", false))
     {
         RemotingMockService.AddMockingUri("http://*/*?id=5");
         Assert.IsTrue(RemotingMockService.IsUriToMock("http://localhost/service.rem?id=5"));
         Assert.IsFalse(RemotingMockService.IsUriToMock("http://localhost/service.rem?id=6"));
         Assert.IsFalse(RemotingMockService.IsUriToMock("tcp://localhost/service.rem?id=5"));
     }
 }
Esempio n. 22
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();
     }
 }
 public void CustomMockingScenarioTest()
 {
     using (RecorderManager.NewPlayBackSession("test", false))
     {
         MockService.AddTypeToMock(typeof(Sample.CustomizableCurrencyService));
         Sample.ICurrencyService srv = Sample.CurrencyServiceFactory.NextInstance;
         decimal result = srv.ConvertAmount(100, Sample.CurrencyUnit.NULL, Sample.CurrencyUnit.GBP);
         Assert.AreEqual(100m, result);
     }
 }
Esempio n. 24
0
 public void MockNotCreatedTest()
 {
     // When type not added with AddTypeToMock...
     using (RecorderManager.NewRecordingSession("test"))
     {
         Assert.AreEqual(RecorderState.Recording, RecorderManager.Action);
         Sample.Account acc = new Sample.Account(Sample.CurrencyUnit.EUR);
         Assert.IsFalse(MockService.IsMock(acc));
     }
 }
Esempio n. 25
0
 public void MockCreatedTest()
 {
     using (RecorderManager.NewRecordingSession("test"))
     {
         Assert.AreEqual(RecorderState.Recording, RecorderManager.Action);
         MockService.AddTypeToMock(typeof(Sample.Account));
         Sample.Account acc = new Sample.Account(Sample.CurrencyUnit.EUR);
         Assert.IsTrue(MockService.IsMock(acc));
     }
 }
 public void DeepCustomMockingTest()
 {
     using (RecorderManager.NewPlayBackSession("test", false))
     {
         MockService.AddTypeToMock(typeof(Sample.CustomizableCurrencyService));
         Sample.Account acc = new Sample.Account(Sample.CurrencyUnit.EUR);
         acc.Deposit(100m);
         acc.SwitchCurrency(Sample.CurrencyUnit.USD);
         Assert.AreEqual(100m, acc.Balance);
     }
 }
Esempio n. 27
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);
        }
Esempio n. 29
0
 public void PlaybackTest()
 {
     Support.RecorderListener listener = new Support.RecorderListener();
     RecorderManager.BeginPlayBack("test");
     using (new RecorderManager.Lock())
     {
     }
     RecorderManager.EndPlayBack();
     Assert.AreEqual(1, listener.BeginPlaybackCounter);
     Assert.AreEqual(1, listener.EndPlaybackCounter);
 }
        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);
        }