コード例 #1
0
ファイル: MessagingTests.cs プロジェクト: ildika/sn-security
        public void Messaging_BigActivity()
        {
            SnLog.Instance = new TestLogger();

            //---- Ensure test data
            var entities    = CreateTestEntities();
            var groups      = SystemStartTests.CreateTestGroups();
            var memberships = Tools.CreateInMemoryMembershipTable(groups);
            var aces        = CreateTestAces();
            var storage     = new DatabaseStorage
            {
                Aces        = aces,
                Memberships = memberships,
                Entities    = entities,
                Messages    = new List <Tuple <int, DateTime, byte[]> >()
            };

            //---- Start the system
            var msgProvider = new TestMessageProvider();

            msgProvider.Initialize();
            Context.StartTheSystem(new MemoryDataProviderForMessagingTests(storage), msgProvider);

            context = new Context(TestUser.User1);

            // small activity
            var smallActivity = new TestActivity();

            smallActivity.Execute(context.Security);
            var smallActivityId = smallActivity.Id;

            // large activity
            var largeActivity = new TestActivity()
            {
                Body = new String('*', Configuration.DistributableSecurityActivityMaxSize + 1)
            };

            largeActivity.Execute(context.Security);
            var largeActivityId = largeActivity.Id;

            // check the logger
            var expected = String.Format("Executing unprocessed security activities., " +
                                         "Send: TestActivity, Applied: #{0}, " +
                                         "Send: BigActivityMessage, LoadMessage: TestActivity#{1}, Applied: #{1}",
                                         smallActivityId, largeActivityId);

            var testLogger = (TestLogger)SnLog.Instance;
            var actual     = string.Join(", ", testLogger.Informations);

            Assert.AreEqual(expected, actual);
        }
コード例 #2
0
        public void Messaging_MessageSender()
        {
            SnLog.Instance = new TestLogger();

            //---- Ensure test data
            var entities    = CreateTestEntities();
            var groups      = SystemStartTests.CreateTestGroups();
            var memberships = Tools.CreateInMemoryMembershipTable(groups);
            var aces        = CreateTestAces();
            var storage     = new DatabaseStorage
            {
                Aces        = aces,
                Memberships = memberships,
                Entities    = entities,
                Messages    = new List <Tuple <int, DateTime, byte[]> >()
            };

            //---- Start the system
            var messageSenderManager = new MessageSenderManager();
            var msgProvider          = new TestMessageProvider(messageSenderManager);

            msgProvider.MessageReceived += MsgProvider_MessageReceived;
            msgProvider.Initialize();

            var securitySystem = Context.StartTheSystem(new MemoryDataProviderForMessagingTests(storage), msgProvider);

            _context = new Context(TestUser.User1, securitySystem);

            // small activity from me
            var activity1 = new TestActivity();

            activity1.Execute(_context.Security);

            // small activity from another
            var activity2 = new TestActivity
            {
                Sender = new TestMessageSender {
                    ComputerID = Environment.MachineName, InstanceID = "AnotherAppDomain"
                }
            };

            activity2.Execute(_context.Security);

            Assert.AreEqual("true, false", string.Join(", ", msgProvider.ReceiverMessages));
        }