Ejemplo n.º 1
0
        public void GetDueDateTest()
        {
            var actionHelper = CreateActionHelper();
            const string dueDateFieldName = "DueDate";

            var dueDate = actionHelper.GetDueDate(Mock.Create<IApprovalActionDefinition>(), Mock.Create<IEditableRoot>());

            Assert.AreEqual(DateTime.MinValue, dueDate);

            var itemMock = new DynamicMock();

            itemMock.SetCanReadProperty("FirstName", true);
            itemMock.SetCanReadProperty("LastName", false);
            itemMock.SetCanReadProperty("DueDate", true);
            
            itemMock.DueDate = new DateTime(2012, 1, 16);

            var actionMock = Mock.Create<IAssignmentActionDefinition>();

            Mock.Arrange(() => actionMock.DueDateFieldName).Returns(dueDateFieldName);

            dueDate = actionHelper.GetDueDate(actionMock, itemMock);

            Assert.AreEqual(itemMock.DueDate, dueDate);

            itemMock.DueDate = null;

            dueDate = actionHelper.GetDueDate(actionMock, itemMock);

            Assert.AreEqual(DateTime.MinValue, dueDate);
        }
Ejemplo n.º 2
0
 public void CreateMockForMBRClass()
 {
     DynamicMock classMock = new DynamicMock( typeof( MBRClass ) );
     MBRClass classInstance = (MBRClass)classMock.MockInstance;
     classMock.Expect( "SomeMethod" );
     classMock.ExpectAndReturn( "AnotherMethod", "Hello World", 5, "hello" );
     classMock.ExpectAndReturn( "MethodWithParams", 42, new object[] { new string[] { "the", "answer" } } );
     classInstance.SomeMethod();
     Assert.AreEqual( "Hello World", classInstance.AnotherMethod( 5, "hello" ) );
     Assert.AreEqual( 42, classInstance.MethodWithParams( "the", "answer" ) );
     classMock.Verify();
 }
Ejemplo n.º 3
0
        public void SetUp()
        {
            _mockFormatter = new DynamicMock(typeof(IFormatterCatalog));
            _mockRenderer  = new DynamicMock(typeof(ICodeRenderer));

            _box = new TestingCodeBox((IFormatterCatalog)_mockFormatter.MockInstance,
                                      (ICodeRenderer)_mockRenderer.MockInstance);
            _box.Width  = 150;
            _box.Height = 150;

//            _emptyText = Format("", "");
            _someText = Format("some C# code", "");
            _someCode = Format("some C# code", "C#");

            return;
        }
Ejemplo n.º 4
0
        public void AdvisedSupportListenerMethodsAre_NOT_CalledIfProxyHasNotBeenCreated()
        {
            IDynamicMock            mock     = new DynamicMock(typeof(IAdvisedSupportListener));
            IAdvisedSupportListener listener = (IAdvisedSupportListener)mock.Object;

            ProxyFactory factory = new ProxyFactory(new TestObject());

            factory.AddListener(listener);

            // must not fire the AdviceChanged callback...
            factory.AddAdvice(new NopInterceptor());
            // must not fire the InterfacesChanged callback...
            factory.AddInterface(typeof(ISerializable));

            mock.Verify();
        }
Ejemplo n.º 5
0
        public void TestDeleteDistrictWithOutCityIn()
        {
            List <City> cities = _GetCities();


            DynamicMock dynamicMock = new DynamicMock(typeof(LocationsManager));

            dynamicMock.SetReturnValue("GetCities", cities);
            dynamicMock.Expect("DeleteDistrictById", 8);


            LocationsManager mocklocationManager = (LocationsManager)dynamicMock.MockInstance;
            LocationServices locationService     = new LocationServices(mocklocationManager);

            Assert.AreEqual(true, locationService.DeleteDistrict(8));
        }
Ejemplo n.º 6
0
        public void GetTarget()
        {
            SideEffectObject target = new SideEffectObject();
            IDynamicMock     mock   = new DynamicMock(typeof(IObjectFactory));;

            mock.ExpectAndReturn("IsPrototype", true, "foo");
            mock.ExpectAndReturn("GetObject", target, "foo");
            mock.ExpectAndReturn("GetType", typeof(string), "foo");
            PrototypeTargetSource source = new PrototypeTargetSource();

            source.TargetObjectName = "foo";
            source.ObjectFactory    = (IObjectFactory)mock.Object;
            Assert.IsTrue(object.ReferenceEquals(source.GetTarget(), target),
                          "Initial target source reference not being returned by GetTarget().");
            mock.Verify();
        }
Ejemplo n.º 7
0
        private void PrepareGoToTransferPageMocks()
        {
            browserMock.ExpectAndReturn("get_Document", documentMock.MockInstance);
            DynamicMock window = AddElementMock(typeof(IHTMLWindow2));

            documentMock.ExpectAndReturn("get_parentWindow", window.MockInstance);

            if (paymentInfo.IsDefinedTransfer == false)
            {
                window.Expect("execScript", "clickMenu('pay_transfer_normal')", "JScript");
            }
            else
            {
                window.Expect("execScript", "clickMenu('pay_payment_list')", "JScript");
            }
        }
        public void ShouldDoNothingOnExecute()
        {
            DynamicMock webBrowserMock = new DynamicMock(typeof(IE.WebBrowser));

            webBrowserMock.ExpectAndReturn("get_LocationURL", Settings.Default.ChoseBankLink + Settings.Default.PluginVersion);

            PaymentInfo info = new PaymentInfo();

            info.State = State.IDLE;
            PaymentProvider provider = GetProvider();

            PaymentInfo result = provider.Execute(new PaymentRequest(webBrowserMock.MockInstance as IE.WebBrowser, info));

            Assert.AreSame(info, result);
            webBrowserMock.Verify();
        }
        public void ShouldExecute()
        {
            DynamicMock webBrowserMock = new DynamicMock(typeof(IE.WebBrowser));

            webBrowserMock.ExpectAndReturn("get_LocationURL", null);

            PaymentInfo info = new PaymentInfo();

            info.State = State.IDLE;
            PaymentProvider provider = GetProvider();

            PaymentInfo result = provider.Execute(new PaymentRequest(webBrowserMock.MockInstance as IE.WebBrowser, info));

            Assert.AreSame(info, result);
            webBrowserMock.Verify();
        }
        private void PrepareDefinedTransferPageMocks(bool result)
        {
            browserMock.ExpectAndReturn("get_Document", documentMock.MockInstance);

            DynamicMock mock = AddElementMock(typeof(IHTMLElementCollection));

            if (result == false)
            {
                mock.ExpectAndReturn("get_length", 0);
            }
            else
            {
                mock.ExpectAndReturn("get_length", 1);
            }
            documentMock.ExpectAndReturn("getElementsByName", mock.MockInstance, Pekao24Provider.DEFINED_TRANSFERS_LIST);
        }
        public void ShouldCallDelegateTransformerWithCorrectFileNames()
        {
            DynamicMock delegateMock     = new DynamicMock(typeof(IMultiTransformer));
            DynamicMock pathProviderStub = new DynamicMock(typeof(IPhysicalApplicationPathProvider));

            PathMappingMultiTransformer transformer = new PathMappingMultiTransformer((IPhysicalApplicationPathProvider)pathProviderStub.MockInstance, (IMultiTransformer)delegateMock.MockInstance);

            pathProviderStub.ExpectAndReturn("GetFullPathFor", @"c:\myAppPath\xslFile1", "xslFile1");
            pathProviderStub.ExpectAndReturn("GetFullPathFor", @"c:\myAppPath\xslFile2", "xslFile2");

            delegateMock.ExpectAndReturn("Transform", "output", "myInput", new string[] { @"c:\myAppPath\xslFile1", @"c:\myAppPath\xslFile2" }, null);

            Assert.AreEqual("output", transformer.Transform("myInput", new string[] { "xslFile1", "xslFile2" }, null));
            pathProviderStub.Verify();
            delegateMock.Verify();
        }
        public void Setup()
        {
            Teardown();
            Directory.CreateDirectory("testtemplates");
            using (var writer = new StreamWriter(@"testtemplates\testtemplate.vm"))
            {
                writer.Write("foo is $foo");
                writer.Flush();
                writer.Close();
            }

            configurationMock = new DynamicMock(typeof(IConfigureTheTransformer));
            configurationMock.SetupResult("TemplateDirectory", "testtemplates");
            viewTransformer =
                new LazilyInitialisingVelocityTransformer((IConfigureTheTransformer)configurationMock.MockInstance);
        }
        public void SetupController()
        {
            mockCustomerRepo      = new DynamicMock(typeof(ICustomerRepository));
            mockEmployeeRepo      = new DynamicMock(typeof(IEmployeeRepository));
            mockServiceTicketRepo = new DynamicMock(typeof(IServiceTicketRepository));
            mockLogEntryRepo      = new DynamicMock(typeof(IServiceLogEntryRepository));
            mockScheduleItemRepo  = new DynamicMock(typeof(IScheduleItemRepository));

            controller = new ServiceTicketsController(
                mockCustomerRepo.MockInstance as ICustomerRepository,
                mockEmployeeRepo.MockInstance as IEmployeeRepository,
                mockServiceTicketRepo.MockInstance as IServiceTicketRepository,
                mockLogEntryRepo.MockInstance as IServiceLogEntryRepository,
                mockScheduleItemRepo.MockInstance as IScheduleItemRepository
                );
        }
Ejemplo n.º 14
0
        public void TestSave()
        {
            Document dm = new Document();

            dm.Text = "abc";

            dm.FileName = @"c:\abc.wordo";

            DynamicMock fs = new DynamicMock(typeof(IFileSystem));

            fs.Expect("WriteAllText", @"c:\abc.wordo", "abc");

            dm.Save((IFileSystem)fs.MockInstance);

            fs.Verify();
        }
Ejemplo n.º 15
0
        public void TestLoad()
        {
            Document dm = new Document();

            dm.FileName = @"c:\abc.wordo";

            DynamicMock fs = new DynamicMock(typeof(IFileSystem));

            fs.ExpectAndReturn("ReadAllText", "abc", @"c:\abc.wordo");

            dm.Load((IFileSystem)fs.MockInstance);

            fs.Verify();

            Assert.AreEqual("abc", dm.Text);
        }
Ejemplo n.º 16
0
        public void CanAddDecorator()
        {
            DynamicMock mock = new DynamicMock(typeof(ITestDecorator));

            mock.Expect("Decorate");

            IExtensionPoint ep = host.GetExtensionPoint("TestDecorators");

            ep.Install(mock.MockInstance);

            ITestDecorator decorators = (ITestDecorator)ep;

            decorators.Decorate(null, null);

            mock.Verify();
        }
Ejemplo n.º 17
0
        public void CanAddTestCaseBuilder2()
        {
            DynamicMock mock = new DynamicMock(typeof(ITestCaseBuilder2));

            mock.ExpectAndReturn("CanBuildFrom", true, null);
            mock.Expect("BuildFrom");

            IExtensionPoint ep = host.GetExtensionPoint("TestCaseBuilders");

            ep.Install(mock.MockInstance);
            ITestCaseBuilder2 builders = (ITestCaseBuilder2)ep;

            builders.BuildFrom(null, null);

            mock.Verify();
        }
 private void PrepareAccountsListPageMocks(bool result)
 {
     if (result == false)
     {
         DynamicMock frames = AddElementMock(typeof(FramesCollection));
         documentMock.ExpectAndReturn("get_frames", frames.MockInstance);
         documentMock.ExpectAndReturn("get_frames", frames.MockInstance);
         frames.ExpectAndReturn("get_length", 2);
     }
     else
     {
         documentMock.ExpectAndReturn("get_frames", null);
         documentMock.ExpectAndReturn("get_frames", null);
         documentMock.ExpectAndReturn("get_url", "someFakeUrl" + MBankProvider.ACCOUNTS_LIST);
     }
 }
 private void PrepareDefinedTransfersPageMocks(bool result)
 {
     if (result == false)
     {
         DynamicMock frames = AddElementMock(typeof(FramesCollection));
         documentMock.ExpectAndReturn("get_frames", frames.MockInstance);
         documentMock.ExpectAndReturn("get_frames", frames.MockInstance);
         frames.ExpectAndReturn("get_length", 2);
     }
     else
     {
         documentMock.ExpectAndReturn("get_frames", null);
         documentMock.ExpectAndReturn("get_frames", null);
         documentMock.ExpectAndReturn("get_url", "someFakeUrl" + MBankProvider.DEFINED_TRANSFERS_LIST);
     }
 }
        private void PrepareInProgressConfirmMocks(String innerHtml, bool nullDiv)
        {
            PrepareLoggedUserMocks();
            DynamicMock elementMock = AddElementMock(typeof(IHTMLElement));

            if (nullDiv == true)
            {
                documentMock.ExpectAndReturn("getElementById", null, "msg");
            }
            else
            {
                elementMock.ExpectAndReturn("get_innerHTML", innerHtml);
                documentMock.ExpectAndReturn("getElementById", elementMock.MockInstance, "msg");
            }
            browserMock.ExpectAndReturn("get_Document", documentMock.MockInstance);
        }
        public void ShouldAddQuotesToStringFromVersionAssemblyProviderForFingerprintFromDate()
        {
            string      testETag            = "test e tag value";
            DateTime    testDate            = new DateTime(2007, 4, 20);
            DynamicMock mockVersionProvider = new DynamicMock(typeof(IVersionProvider));

            mockVersionProvider.SetupResult("GetVersion", testETag);

            ConditionalGetFingerprint testConditionalGetFingerprint =
                new FingerprintFactory((IVersionProvider)mockVersionProvider.MockInstance, null).BuildFromDate(testDate);


            string expectedETag = "\"" + testETag + "\"";

            Assert.AreEqual(expectedETag, testConditionalGetFingerprint.ETag);
        }
Ejemplo n.º 22
0
        public void Sample_MethodResultIsDto()
        {
            dynamic isolated = new DynamicMock();

            isolated.LoadSomeDtoWithVeryLongName().Returns(new { Id = 42, Name = "subbotnik" });

            ISampleInterface result = isolated;

            var actual = result.LoadSomeDtoWithVeryLongName();

            var expected = new SomeDtoWithVeryLongName {
                Id = 42, Name = "subbotnik"
            };

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 23
0
        public void DefaultVisualStudioShouldBe2005IfNothingNewerInstalled()
        {
            IMock mockRegistry2 = new DynamicMock(typeof(IRegistry));

            DevenvTask task2 = new DevenvTask((IRegistry)mockRegistry2.MockInstance, (ProcessExecutor)mockProcessExecutor.MockInstance);

            mockRegistry2.ExpectAndReturn("GetLocalMachineSubKeyValue", null, DevenvTask.VS2013_REGISTRY_PATH, DevenvTask.VS_REGISTRY_KEY);
            mockRegistry2.ExpectAndReturn("GetLocalMachineSubKeyValue", null, DevenvTask.VS2012_REGISTRY_PATH, DevenvTask.VS_REGISTRY_KEY);
            mockRegistry2.ExpectAndReturn("GetLocalMachineSubKeyValue", null, DevenvTask.VS2010_REGISTRY_PATH, DevenvTask.VS_REGISTRY_KEY);
            mockRegistry2.ExpectAndReturn("GetLocalMachineSubKeyValue", null, DevenvTask.VS2008_REGISTRY_PATH, DevenvTask.VS_REGISTRY_KEY);
            mockRegistry2.ExpectAndReturn("GetLocalMachineSubKeyValue", DEVENV_2005_PATH,
                                          DevenvTask.VS2005_REGISTRY_PATH, DevenvTask.VS_REGISTRY_KEY);
            Assert.AreEqual(DEVENV_2005_PATH + "devenv.com", task2.Executable);
            mockRegistry2.Verify();
            mockProcessExecutor.Verify();
        }
Ejemplo n.º 24
0
        public void Sample_MethodResultSimplifiedNames()
        {
            dynamic isolated = new DynamicMock();

            isolated.Load_().Returns(new { _Value = 156 });

            ISampleInterface result = isolated;

            var actual = result.LoadSomeDtoWithVeryLongName();

            var expected = new SomeDtoWithVeryLongName {
                VeryLongPropertyButAnywayItMeansValue = 156
            };

            Assert.AreEqual(expected, actual);
        }
        public void ShouldHandleBaseURLsWithTrailingSlashes()
        {
            /// Setup
            DynamicMock decoratedBuilderMock = new DynamicMock(typeof(IUrlBuilder));
            string      baseUrl = "https://myserver:8080/myvdir/";

            AbsolutePathUrlBuilderDecorator decorator = new AbsolutePathUrlBuilderDecorator((IUrlBuilder)decoratedBuilderMock.MockInstance, baseUrl);
            string actionName = "myAction";

            decoratedBuilderMock.ExpectAndReturn("BuildUrl", "myRelativeUrl", actionName);

            /// Execute & Verify
            Assert.AreEqual(baseUrl + "myRelativeUrl", decorator.BuildUrl(actionName));

            decoratedBuilderMock.Verify();
        }
Ejemplo n.º 26
0
        public void IndexReturnsNonNullView()
        {
            var serviceTicketRepo = new DynamicMock(typeof(IServiceTicketRepository));
            var messageRepo       = new DynamicMock(typeof(IMessageRepository));
            var alertRepo         = new DynamicMock(typeof(IAlertRepository));
            var scheduleItemRepo  = new DynamicMock(typeof(IScheduleItemRepository));

            var controller = new HomeController(
                serviceTicketRepo.MockInstance as IServiceTicketRepository,
                messageRepo.MockInstance as IMessageRepository,
                alertRepo.MockInstance as IAlertRepository,
                scheduleItemRepo.MockInstance as IScheduleItemRepository
                );

            var result = (ViewResult)controller.Index();
        }
Ejemplo n.º 27
0
        public void ShouldInstructAggregatedSourceControlsToGetSource()
        {
            IntegrationResult result  = new IntegrationResult();
            IMock             mockSC1 = new DynamicMock(typeof(ISourceControl));
            IMock             mockSC2 = new DynamicMock(typeof(ISourceControl));

            mockSC1.Expect("GetSource", result);
            mockSC2.Expect("GetSource", result);

            MultiSourceControl multiSourceControl = new MultiSourceControl();

            multiSourceControl.SourceControls = new ISourceControl[] { (ISourceControl)mockSC1.MockInstance, (ISourceControl)mockSC2.MockInstance };
            multiSourceControl.GetSource(result);

            mockSC1.Verify();
            mockSC2.Verify();
        }
Ejemplo n.º 28
0
        public void ShouldGetSourceIfAutoGetSourceTrue()
        {
            DynamicMock executor  = new DynamicMock(typeof(ProcessExecutor));
            ClearCase   clearCase = new ClearCase((ProcessExecutor)executor.MockInstance);

            clearCase.Executable    = EXECUTABLE;
            clearCase.ViewPath      = VIEWPATH;
            clearCase.AutoGetSource = true;

            ProcessInfo expectedProcessRequest = new ProcessInfo(EXECUTABLE, @"update -force -overwrite """ + VIEWPATH + @"""");

            expectedProcessRequest.TimeOut = Timeout.DefaultTimeout.Millis;

            executor.ExpectAndReturn("Execute", new ProcessResult("foo", null, 0, false), expectedProcessRequest);
            clearCase.GetSource(new IntegrationResult());
            executor.Verify();
        }
        private void PrepareAnyAccountSelectedMock(bool result)
        {
            if (result == false)
            {
                documentMock.ExpectAndReturn("getElementById", null, "contextInfo");
                return;
            }
            DynamicMock context = AddElementMock(typeof(IHTMLElement));

            documentMock.ExpectAndReturn("getElementById", context.MockInstance, "contextInfo");
            String html = MBankProvider.SPAN_BEGIN + MBankProvider.SPAN_END
                          + MBankProvider.SPAN_BEGIN + MBankProvider.SUPPORTED_ACCOUNTS[0] + MBankProvider.SPAN_END;

            context.ExpectAndReturn("get_innerHTML", html);
            context.ExpectAndReturn("get_innerHTML", html);
            context.ExpectAndReturn("get_innerHTML", html);
        }
Ejemplo n.º 30
0
        public void CanAddEventListener()
        {
            DynamicMock mock = new DynamicMock(typeof(EventListener));

            mock.Expect("RunStarted");
            mock.Expect("RunFinished");

            IExtensionPoint ep = host.GetExtensionPoint("EventListeners");

            ep.Install(mock.MockInstance);
            EventListener listeners = (EventListener)ep;

            listeners.RunStarted("test", 0);
            listeners.RunFinished(new TestResult(new TestInfo(new TestSuite("test"))));

            mock.Verify();
        }
Ejemplo n.º 31
0
        private IParsable CreateMockParser(UInt32 expectedReportItemCount)
        {
            var control = new DynamicMock(typeof(IParsable));

            control.ExpectAndReturn("GetBytes", code, null);

            var reportItemList = new List <ReportItem>();

            for (UInt32 i = 0; i < expectedReportItemCount; i++)
            {
                reportItemList.Add(new ReportItem(i, false));
            }

            control.ExpectAndReturn("get_ExpectedReportItems", reportItemList.AsReadOnly(), null);
            control.ExpectAndReturn("get_ExpectedReportItems", reportItemList.AsReadOnly(), null);
            return(control.MockInstance as IParsable);
        }
        private void PrepareConfirmationPageMocks(bool result)
        {
            PrepareLoggedUserMocks();

            browserMock.ExpectAndReturn("get_Document", documentMock.MockInstance);
            DynamicMock body = AddElementMock(typeof(IHTMLElement));

            if (result == false)
            {
                body.ExpectAndReturn("get_innerHTML", "<tag>something</tag>&nbsp;<MESSAGE></MESSAGE><td></td>");
            }
            else
            {
                body.ExpectAndReturn("get_innerHTML", "<tag>something</tag>&nbsp;<MESSAGE>Zlecenie Przyjêto Do Realizacji.</MESSAGE><td></td>");
            }
            documentMock.ExpectAndReturn("get_body", body.MockInstance);
        }
Ejemplo n.º 33
0
        public void ReplaceSingleCrossReferenceFieldFromBaseProcess()
        {
            // Arrange.
            const string BaseProcessName = "BaseProcess";
            const string DerivedProcessName = "DerivedProcess";
            const string Template = "Test {CRField} Test";
            const string DisplayText = "683A5DEA-08F7-4741-A58B-432F81650152";
            const string Expected = "Test 683A5DEA-08F7-4741-A58B-432F81650152 Test";
            const int CRId = 11;

            var crItem = new CrossReferenceItem { __DisplayName = DisplayText };

            Mock.Arrange(() => _dtm.GetCrossReferenceItem(BaseProcessName, "CRField", CRId)).Returns(crItem);

            var actionHelper = CreateActionHelper();

            var baseEdit = new DynamicMock { ProcessName = BaseProcessName };
            baseEdit.SetCanReadProperty("CRField", true);
            baseEdit.CRField = CRId;
            var item = new DerivedDynamicMock { ProcessName = DerivedProcessName, BaseEdit = baseEdit };

            // Act.
            var result = actionHelper.ReplaceFieldsWithValues(Template, item, false);

            // Assert.
            Assert.AreEqual(Expected, result);
        }
Ejemplo n.º 34
0
        public void WhenSingleCrossReferenceIsBlocked_PrintBlockedContentMessage()
        {
            const string Template = "Test {CRField} Test";

            var expected = string.Format(CultureInfo.InvariantCulture, "Test {0} Test", "&lt;Blocked Content&gt;");

            var item = new DynamicMock();

            item.SetCanReadProperty("CRField", false);
            item.SetCanReadProperty("CRFieldMember", false);
            item.CRField = 3;

            var actionHelper = CreateActionHelper();
            var actual = actionHelper.ReplaceFieldsWithValues(Template, item, true);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 35
0
        public void CreateActionItemInfoTest()
        {
            const int ActionItemId = 123;
            var actionGuid = new Guid("03C09D58-F670-41C2-8E69-750F0A5CB2DF");
            const string Process = "test process";
            const int ItemId = 555;
            const int PersonId = 111;
            const bool IsActionNew = true;
            const int ItemStateId = 2;
            const string ApprovalFieldName = "approvalFieldName";
            const string ActionName = "Action Name";
            const string GroupName = "Group Name";
            const string FirstName = "First Name";
            const string LastName = "Last Name";
            var dueDate = new DateTime(2012, 1, 16);
            var expectedSubject = string.Format(CultureInfo.InvariantCulture, "Test {0} {2} {1} {0}", FirstName, dueDate, "<Blocked Content>");
            var expectedMessage = string.Format(CultureInfo.InvariantCulture, "Test {0} {2} {1} {0}", FirstName, dueDate, "&lt;Blocked Content&gt;");

            var actionHelper = CreateActionHelper();
            var actionItemMock = Mock.Create<IActionItemInfo>();

            Mock.Arrange(() => actionItemMock.Id).Returns(ActionItemId);
            Mock.Arrange(() => actionItemMock.ActionGuid).Returns(actionGuid.ToString());
            Mock.Arrange(() => actionItemMock.Process).Returns(Process);
            Mock.Arrange(() => actionItemMock.ItemId).Returns(ItemId);
            Mock.Arrange(() => actionItemMock.PersonId).Returns(PersonId);
            Mock.Arrange(() => actionItemMock.IsActionNew).Returns(IsActionNew);
            Mock.Arrange(() => actionItemMock.ItemStateId).Returns(ItemStateId);

            var actionDefinitionMock = Mock.Create<IApprovalActionDefinition>();

            Mock.Arrange(() => actionDefinitionMock.ApprovalFieldName).Returns(ApprovalFieldName);
            Mock.Arrange(() => actionDefinitionMock.Guid).Returns(actionGuid);
            Mock.Arrange(() => actionDefinitionMock.Name).Returns(ActionName);
            Mock.Arrange(() => actionDefinitionMock.GroupName).Returns(GroupName);
            Mock.Arrange(() => actionDefinitionMock.GetSubject(Arg.IsAny<IEditableRoot>())).Returns(expectedSubject);
            Mock.Arrange(() => actionDefinitionMock.GetMessageForDashboard(Arg.IsAny<IEditableRoot>())).Returns(expectedMessage);

            var actionManagerMock = Mock.Create<IActionManager>();
            Mock.Arrange(() => actionManagerMock.ActionDefinitions).ReturnsCollection(new List<IActionDefinition> { actionDefinitionMock });
            Mock.Arrange(() => _dtm.GetActionManager(Process)).Returns(actionManagerMock);

            var itemMock = new DynamicMock { DueDate = dueDate, FirstName = FirstName, LastName = LastName, ActionManager = actionManagerMock };

            itemMock.SetCanReadProperty("FirstName", true);
            itemMock.SetCanReadProperty("LastName", false);
            itemMock.SetCanReadProperty("DueDate", true);

            var actionItemInfo = actionHelper.CreateActionItemInfo(actionItemMock, itemMock);

            Assert.AreEqual(ActionItemId, actionItemInfo.Id);
            Assert.AreEqual(actionGuid.ToString(), actionItemInfo.ActionGuid);
            Assert.AreEqual(ActionName, actionItemInfo.Name);
            Assert.AreEqual(expectedSubject, actionItemInfo.Subject);
            Assert.AreEqual(expectedMessage, actionItemInfo.Message);
            Assert.AreEqual(ActionTypes.Approval, actionItemInfo.ActionType);
            Assert.AreEqual(GroupName, actionItemInfo.GroupName);
            Assert.AreEqual(DateTime.MinValue, actionItemInfo.DueDate);
            Assert.AreEqual(IsActionNew, actionItemInfo.IsActionNew);
            Assert.AreEqual(Process, actionItemInfo.ProcessName);
            Assert.AreEqual(ItemId, actionItemInfo.ItemId);
        }
Ejemplo n.º 36
0
        public void ReplaceFileTest()
        {
            // Arrange.
            const string Template = "Prefix {File} suffix.";

            var file = Mock.Create<IFileProcess>(Behavior.Loose);
            Mock.Arrange(() => file.OriginalFileName).Returns("Test File <&>.txt");
            Mock.Arrange(() => file.FileName).Returns("abc.txt");

            var item = new DynamicMock { File = file };
            item.SetCanReadProperty(ReflectionHelper.GetPropertyName<DynamicMock>(x => x.File), true);

            Mock.Arrange(() => _fileHelper.GetFullNavigateUrl("abc.txt")).Returns("http://localhost/DocHandler.ashx?FileName=abc.txt");
            var actionHelper = CreateActionHelper();

            // Act.
            var textResult = actionHelper.ReplaceFieldsWithValues(Template, item);
            var htmlResult = actionHelper.ReplaceFieldsWithValues(Template, item, true);

            // Assert.
            Assert.AreEqual("Prefix Test File <&>.txt suffix.", textResult);
            Assert.AreEqual(
                "Prefix <a href=\"http://localhost/DocHandler.ashx?FileName=abc.txt\" target=\"_blank\">Test File &lt;&amp;&gt;.txt</a> suffix.",
                htmlResult);
        }
Ejemplo n.º 37
0
        public void ReplaceFieldsWithValuesCanReplaceSingleCrossReferenceFields()
        {
            const string ProcessName = "processName";
            const string CRText = "test";
            const int CRNumber = 123;
            const int CRId = 11;
            const string Template = "Test {CRField} Test";

            var crDate = new DateTime(2012, 6, 5);
            var crDisplayText = string.Format(CultureInfo.InvariantCulture, "{0}, {1}, {2}", CRText, CRNumber, crDate);
            var expected = string.Format(CultureInfo.InvariantCulture, "Test {0} Test", crDisplayText);
            var crItem = new DynamicCrossReferenceMock
                {
                    Id = CRId,
                    TextField = CRText,
                    NumericField = CRNumber,
                    DateField = crDate,
                    DisplayText = crDisplayText
                };

            var item = new DynamicMock {ProcessName = ProcessName};

            item.SetCanReadProperty("CRField", true);
            item.CRField = CRId;

            Mock.Arrange(() => _dtm.GetCrossReferenceItem(ProcessName, "CRField", CRId)).Returns(crItem);

            var actionHelper = CreateActionHelper();
            var actual = actionHelper.ReplaceFieldsWithValues(Template, item, true);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 38
0
        public void ReplaceFieldsWithValuesTest()
        {
            var actionHelper = CreateActionHelper();
            const string Template = "Test {FirstName} {LastName} {DueDate} {FirstName}";

            var itemMock = new DynamicMock();

            itemMock.SetCanReadProperty("FirstName", true);
            itemMock.SetCanReadProperty("LastName", false);
            itemMock.SetCanReadProperty("DueDate", true);

            itemMock.DueDate = new DateTime(2012, 1, 16);
            itemMock.FirstName = "First Name";
            itemMock.LastName = "Last Name";

            var expected = string.Format(CultureInfo.InvariantCulture, "Test {0} {2} {1} {0}", itemMock.FirstName, itemMock.DueDate, "&lt;Blocked Content&gt;");

            var actual = actionHelper.ReplaceFieldsWithValues(Template, itemMock, true);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 39
0
		public void CreateMockForNonMBRClassFails()
		{
			DynamicMock classMock = new DynamicMock( typeof( NonMBRClass ) );
			instance = classMock.MockInstance as IStuff;
		}
Ejemplo n.º 40
0
		public void CreateMock()
		{
			mock = new DynamicMock( typeof( IStuff ) );
			instance = (IStuff)mock.MockInstance;
		}
Ejemplo n.º 41
0
		public void MockHasNonDefaultName()
		{
			DynamicMock mock2 = new DynamicMock( "MyMock", typeof( IStuff ) );
			Assert.AreEqual( "MyMock", mock2.Name );
		}
Ejemplo n.º 42
0
        public void WhenSingleCrossReferenceFieldIsNull_UseEmptyString()
        {
            const string Template = "Test {CRField} Test";

            var expected = string.Format(CultureInfo.InvariantCulture, "Test  Test");

            var item = new DynamicMock();

            item.SetCanReadProperty("CRField", true);
            item.SetCanReadProperty("CRFieldMember", true);
            item.CRField = null;

            var actionHelper = CreateActionHelper();
            var actual = actionHelper.ReplaceFieldsWithValues(Template, item, true);

            Assert.AreEqual(expected, actual);
        }