Exemplo n.º 1
0
        public void Fake()
        {
            SetupMock();

            var plugin = new UpdateActivitiesRefactored();

            //Act
            plugin.Execute(_serviceProvider);


            //Assert
            Assert.AreEqual(_organizationServiceFake.GetEntity(new Id <Email>(_email1Guid)).StateCode, EmailState.Open);
            Assert.AreEqual(DateTime.Now.Date.AddDays(NumberOfDaysDifference), _organizationServiceFake.GetEntity(new Id <Email>(_email1Guid)).ScheduledStart, "Start date not updated correctly for emails with a subject");

            Assert.AreEqual(_organizationServiceFake.GetEntity(new Id <Email>(_email2Guid)).StateCode, EmailState.Open);
            Assert.AreEqual(DateTime.Now.Date.AddDays(NumberOfDaysDifference), _organizationServiceFake.GetEntity(new Id <Email>(_email2Guid)).ScheduledStart, "Start date not updated correctly for emails with a subject");

            Assert.AreEqual(EmailState.Canceled, _organizationServiceFake.GetEntity(new Id <Email>(_email3Guid)).StateCode, "Email without a subject was not cancelled");

            _tracingMock.Verify(trace => trace.Trace("{0} closed emails and {1} updated emails", 1, 2), Times.Exactly(1));
        }
Exemplo n.º 2
0
        public void TestMethod1()
        {
            var serviceProviderMock = new Mock <IServiceProvider>();
            var traceServiceMock    = new Mock <ITracingService>();

            //Plugin Context
            var pluginContextMock = new Mock <IPluginExecutionContext>();
            //pluginContextMock.Setup(c => c.UserId).Returns(new Guid());

            //Target InputParameter for plugin context
            var parameterCollection = new ParameterCollection();

            parameterCollection.Add("Target", new Account()
            {
                Id = Guid.NewGuid()
            });
            pluginContextMock.Setup(c => c.InputParameters).Returns(parameterCollection);

            //Organisation Service
            var organisationServiceMock = new Mock <IOrganizationService>();
            var entityCollection        = new EntityCollection();

            entityCollection.Entities.Add(new Email()
            {
                Id = Guid.NewGuid(), Subject = "Mock 1"
            });
            entityCollection.Entities.Add(new Email()
            {
                Id = Guid.NewGuid(), Subject = "Mock 2"
            });
            entityCollection.Entities.Add(new Email()
            {
                Id = Guid.NewGuid()
            });
            organisationServiceMock.Setup(s => s.RetrieveMultiple(It.IsAny <QueryBase>())).Returns(entityCollection);


            //Factory
            var organisationServicefactoryMock = new Mock <IOrganizationServiceFactory>();

            organisationServicefactoryMock.Setup(f => f.CreateOrganizationService(It.IsAny <Guid>())).Returns(organisationServiceMock.Object);

            //Set up provider mothods
            serviceProviderMock.Setup(sp => sp.GetService(typeof(ITracingService))).Returns(traceServiceMock.Object);
            serviceProviderMock.Setup(sp => sp.GetService(typeof(IPluginExecutionContext))).Returns(pluginContextMock.Object);
            serviceProviderMock.Setup(sp => sp.GetService(typeof(IOrganizationServiceFactory))).Returns(organisationServicefactoryMock.Object);


            var plugin = new UpdateActivitiesRefactored();

            plugin.Execute(serviceProviderMock.Object);

            //var iserviceProvider = new IServiceProvider();
            //plugin.Execute();


            //Context validation
            organisationServiceMock.Verify(dal => dal.Execute(It.IsAny <SetStateRequest>()), Times.Exactly(1));
            organisationServiceMock.Verify(dal => dal.Update(It.IsAny <Entity>()), Times.Exactly(2));
            traceServiceMock.Verify(trace => trace.Trace("{0} closed emails and {1} updated emails", 1, 2), Times.Exactly(1));
        }