Esempio n. 1
0
        public void CheckServerCount_EPMServersGreaterThanServerCount_ReturnsBoolean()
        {
            // Arrange
            const int    serverCount = 1;
            const string keyString   = "EPMLiveServers";
            const string servers     = "server1,server2,server3";

            var server = new ShimSPServer()
            {
                RoleGet = () => SPServerRole.WebFrontEnd
            };
            var hashTable = new Hashtable()
            {
                [keyString] = servers
            };

            spFarm.ServersGet = () => new ShimSPServerCollection();
            ShimSPPersistedObjectCollection <SPServer> .AllInstances.GetEnumerator = _ => new List <SPServer>()
            {
                server,
                server
            }.GetEnumerator();
            ShimSPPersistedObject.AllInstances.PropertiesGet = _ => hashTable;

            // Act
            var actual = (bool)privateObject.Invoke(
                CheckServerCountMethodName,
                BindingFlags.Static | BindingFlags.NonPublic,
                new object[] { serverCount, true });

            // Assert
            actual.ShouldBeFalse();
        }
Esempio n. 2
0
        public void CheckServerCount_FarmServersLessThanServerCount_ReturnsBoolean()
        {
            // Arrange
            const int serverCount = 10;

            var server = new ShimSPServer()
            {
                RoleGet = () => SPServerRole.WebFrontEnd
            };

            spFarm.ServersGet = () => new ShimSPServerCollection();
            ShimSPPersistedObjectCollection <SPServer> .AllInstances.GetEnumerator = _ => new List <SPServer>()
            {
                server,
                server
            }.GetEnumerator();

            // Act
            var actual = (bool)privateObject.Invoke(
                CheckServerCountMethodName,
                BindingFlags.Static | BindingFlags.NonPublic,
                new object[] { serverCount, true });

            // Assert
            actual.ShouldBeTrue();
        }
Esempio n. 3
0
        public void CheckServerCount_EPMServersLessThanServerCount_ReturnsBoolean()
        {
            // Arrange
            const int    serverCount = 3;
            const string keyString   = "EPMLiveServers";
            const string servers     = "server1,server2";
            const string serverName  = "server2";

            var methodHit = false;
            var server    = new ShimSPServer()
            {
                RoleGet = () => SPServerRole.WebFrontEnd
            };
            var hashTable = new Hashtable()
            {
                [keyString] = servers
            };

            spFarm.ServersGet = () => new ShimSPServerCollection();
            ShimSPPersistedObjectCollection <SPServer> .AllInstances.GetEnumerator = _ => new List <SPServer>()
            {
                server,
                server,
                server,
                server
            }.GetEnumerator();
            ShimDns.GetHostName = () =>
            {
                methodHit = true;
                return(serverName);
            };
            ShimSPPersistedObject.AllInstances.PropertiesGet = _ => hashTable;

            // Act
            var actual = (bool)privateObject.Invoke(
                CheckServerCountMethodName,
                BindingFlags.Static | BindingFlags.NonPublic,
                new object[] { serverCount, true });

            // Assert
            actual.ShouldSatisfyAllConditions(
                () => actual.ShouldBeTrue(),
                () => methodHit.ShouldBeTrue());
        }
        public void SendEmail_DisposesProperly()
        {
            // Arrange
            var writerDisposeCalled = false;
            var smtpDisposeCalled   = false;
            var sendCalled          = false;

            ShimSmtpClient.AllInstances.SendMailMessage = (_1, _2) =>
            {
                if (smtpDisposeCalled)
                {
                    throw new InvalidOperationException("Smtp Client shouldn't dispose before sending");
                }
                sendCalled = true;
            };
            ShimSmtpClient.AllInstances.Dispose  = _ => smtpDisposeCalled = true;
            ShimMailMessage.AllInstances.Dispose = _ =>
            {
                if (!smtpDisposeCalled ||
                    !sendCalled)
                {
                    throw new InvalidOperationException("Mail Message can only be disposed after client send message and properly disposed");
                }
                writerDisposeCalled = true;
            };

            ShimSPAdministrationWebApplication.LocalGet = () =>
            {
                var spAdministrationWebApplication = new ShimSPAdministrationWebApplication();
                var spWebApplication = new ShimSPWebApplication(spAdministrationWebApplication)
                {
                    OutboundMailServiceInstanceGet = () =>
                    {
                        var spOutboundMailServiceInstance = new ShimSPOutboundMailServiceInstance();
                        var spServiceInstance             = new ShimSPServiceInstance(spOutboundMailServiceInstance)
                        {
                            ServerGet = () =>
                            {
                                var spServer      = new ShimSPServer();
                                var spPersistedOb = new ShimSPPersistedObject(spServer)
                                {
                                    NameGet = () => DummyServerName
                                };
                                return(spServer);
                            }
                        };
                        return(spOutboundMailServiceInstance);
                    }
                };
                return(spAdministrationWebApplication);
            };

            ShimSPSecurity.RunWithElevatedPrivilegesSPSecurityCodeToRunElevated = code => code();

            // Act
            _privateObject.Invoke(
                SendEmailMethodName,
                DummyUserEmail,
                DummyFromEmail,
                DummySubject,
                DummyUserDisplayName);

            // Assert
            this.ShouldSatisfyAllConditions(
                () => writerDisposeCalled.ShouldBeTrue(),
                () => smtpDisposeCalled.ShouldBeTrue(),
                () => sendCalled.ShouldBeTrue());
        }
        public void Execute_Always_SetExpectedValues()
        {
            // Arrange
            var shimSpWeb = ArrangeForExecute();
            var shim      = new ShimSPWebCollection();
            var list      = new List <SPWeb>
            {
                ArrangeForExecute()
            };

            new ShimSPBaseCollection(shim)
            {
                GetEnumerator = () => list.GetEnumerator()
            };
            shimSpWeb.WebsGet = () => shim;
            var shimSite = new ShimSPSite
            {
                RootWebGet = () => shimSpWeb
            };

            ShimSPSecurity.RunWithElevatedPrivilegesSPSecurityCodeToRunElevated =
                codeToRun => codeToRun();
            ShimSPAdministrationWebApplication.LocalGet = () =>
            {
                var shimSPAdministrationWebApplication = new ShimSPAdministrationWebApplication();
                new ShimSPWebApplication(shimSPAdministrationWebApplication)
                {
                    OutboundMailServiceInstanceGet = () =>
                    {
                        var shimSPOutboundMailServiceInstance = new ShimSPOutboundMailServiceInstance();
                        new ShimSPServiceInstance(shimSPOutboundMailServiceInstance)
                        {
                            ServerGet = () =>
                            {
                                var shimSPServer = new ShimSPServer();
                                new ShimSPPersistedObject(shimSPServer)
                                {
                                    NameGet = () => "SPPersistedObject"
                                };
                                return(shimSPServer);
                            }
                        };
                        return(shimSPOutboundMailServiceInstance);
                    }
                };
                return(shimSPAdministrationWebApplication);
            };
            ShimMailAddress.ConstructorString = (instance, address) => new ShimMailAddress(instance);
            ShimSmtpClient.Constructor        = instance => new ShimSmtpClient(instance)
            {
                SendMailMessage = mailMessage => { }
            };
            ShimSqlConnection.AllInstances.Open         = instance => { };
            ShimSqlCommand.AllInstances.ExecuteNonQuery = instance => 0;
            var data = string.Empty;

            _notifications.EmailSubject      = null;
            _notifications.FromEmail         = null;
            _notifications.LogDetailedErrors = true;

            // Act
            _notifications.execute(
                shimSite,
                shimSpWeb,
                data);

            // Assert
            this.ShouldSatisfyAllConditions(
                () => ((string)_privateObject.GetFieldOrProperty("sMainURL")).ShouldBe(SpWebUrl),
                () => _notifications.FromEmail.ShouldBe("EPMLiveNotificationEmail"),
                () => _notifications.EmailSubject.ShouldBe("EPMLiveNotificationEmailSubject"),
                () => _notifications.LogDetailedErrors.ShouldBeFalse(),
                () => _notifications.ErrorLogDetailLevel.ShouldBe(ErrorLogDetailLevelEnum.SectionLevelErrors));
        }