コード例 #1
0
        public async Task Async_Long_IsOrdered()
        {
            var testableLogger   = new TestableLogger();
            var containerManager = new TestContainerManager(
                container => {
                var settingsServiceRegistration = Lifestyle.Singleton.CreateRegistration(() => testableLogger, container);
                container.RegisterConditional(typeof(ILogger), settingsServiceRegistration, pc => !pc.Handled);
            });
            var factory         = containerManager.Container.GetInstance <ReceivedFactory>();
            var pipelineManager = containerManager.Container.GetInstance <IPipelineManager>();
            var data            = new List <IReceived <IUser, ITransmittable> > {
                factory.ModPublicReceivedMessage("!long"),
                factory.ModPublicReceivedMessage("!long"),
                factory.ModPublicReceivedMessage("!long"),
            };

            data.ForEach(x => pipelineManager.Enqueue(x));

            await Task.Delay(15000);

            var results = testableLogger.Outbox.Where(s => s == "#1" || s == "#2" || s == "#3").ToList();

            Assert.AreEqual(9, results.Count);
            var alphabetized = results.OrderBy(q => q).ToList();

            Assert.IsTrue(results.SequenceEqual(alphabetized));
        }
コード例 #2
0
 public void InitialUsers_ParsesPublicMessages_WithoutError()
 {
     var data      = TestData.DestinyGgPublicMsg;
     var container = new TestContainerManager();
     var parser    = container.Container.GetInstance <DestinyGgParser>();
     var received  = parser.Create(data);
 }
コード例 #3
0
        public void PunishedUserWithNoPriors_Increment_CountIs1()
        {
            var container            = new TestContainerManager().InitializeAndIsolateRepository();
            var id                   = TestHelper.RandomInt();
            var term                 = TestHelper.RandomString();
            var type                 = TestHelper.RandomAutoPunishmentType();
            var duration             = TestHelper.RandomInt();
            var nick                 = TestHelper.RandomString();
            var autoPunishmentEntity = new AutoPunishmentEntity {
                Id       = id,
                Term     = term,
                Type     = type,
                Duration = duration,
            };

            var repository = container.GetInstance <IQueryCommandService <IUnitOfWork> >();

            repository.Command(r => r.AutoPunishments.Add(new AutoPunishment(autoPunishmentEntity)));

            repository.Command(db => db.PunishedUsers.Increment(nick, term));

            var user = repository.Query(db => db.PunishedUsers.GetUser(nick));

            Assert.AreEqual(1, user.Count);
        }
コード例 #4
0
        public void ReadWriteUpdateAutoPunishment()
        {
            var container = new TestContainerManager().InitializeAndIsolateRepository();

            var id                   = TestHelper.RandomInt();
            var term                 = TestHelper.RandomString();
            var type                 = TestHelper.RandomAutoPunishmentType();
            var duration             = TestHelper.RandomInt();
            var nick                 = TestHelper.RandomString();
            var count                = TestHelper.RandomInt();
            var autoPunishmentEntity = new AutoPunishmentEntity {
                Id       = id,
                Term     = term,
                Type     = type,
                Duration = duration,
            };
            var punishedUsersEntity = new List <PunishedUserEntity> {
                new PunishedUserEntity {
                    Nick = nick, Count = count, AutoPunishmentEntity = autoPunishmentEntity
                }
            };
            var repository = container.GetInstance <IQueryCommandService <IUnitOfWork> >();

            repository.Command(r => r.AutoPunishments.Add(new AutoPunishment(autoPunishmentEntity)));

            autoPunishmentEntity.Id       = TestHelper.RandomInt();
            autoPunishmentEntity.Term     = TestHelper.RandomString();
            autoPunishmentEntity.Type     = TestHelper.RandomAutoPunishmentType();
            autoPunishmentEntity.Duration = TestHelper.RandomInt();
            nick  = TestHelper.RandomString();
            count = TestHelper.RandomInt();
            autoPunishmentEntity = new AutoPunishmentEntity {
                Id       = id,
                Term     = term,
                Type     = type,
                Duration = duration,
            };
            punishedUsersEntity = new List <PunishedUserEntity> {
                new PunishedUserEntity {
                    Nick = nick, Count = count, AutoPunishmentEntity = autoPunishmentEntity
                }
            };
            autoPunishmentEntity.PunishedUsers = punishedUsersEntity;

            repository.Command(r => r.AutoPunishments.Update(new AutoPunishment(autoPunishmentEntity)));

            var testRead = new List <AutoPunishment>();

            repository.Command(r => {
                testRead.AddRange(r.AutoPunishments.GetAllWithUser);
            });
            var dbAutoPunishment = testRead.Single();

            Assert.AreEqual(dbAutoPunishment.Id, id);
            Assert.AreEqual(dbAutoPunishment.Term, term);
            Assert.AreEqual(dbAutoPunishment.Type, type);
            Assert.AreEqual(dbAutoPunishment.Duration.TotalSeconds, duration);
            Assert.AreEqual(dbAutoPunishment.PunishedUsers.Single().Count, count);
            Assert.AreEqual(dbAutoPunishment.PunishedUsers.Single().Nick, nick);
        }
コード例 #5
0
        public void PeriodicTasks_Run_YieldsAlternatingMessages()
        {
            var errorableDownloadFactory = Substitute.For <IErrorableFactory <string, string, string, string> >();

            errorableDownloadFactory.Create(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>()).Returns(TestData.YoutubeFeed);
            var sender    = new TestableSerializer();
            var container = new TestContainerManager(c => {
                var senderRegistration = Lifestyle.Singleton.CreateRegistration(() => sender, c);
                c.RegisterConditional(typeof(IFactory <IEnumerable <ISendable <ITransmittable> >, IEnumerable <string> >), senderRegistration, _ => true);
                var errorableDownloadFactoryRegistration = Lifestyle.Singleton.CreateRegistration(() => errorableDownloadFactory, c);
                c.RegisterConditional(typeof(IErrorableFactory <string, string, string, string>), errorableDownloadFactoryRegistration, _ => true);
            }, settings => settings.PeriodicMessageInterval = TimeSpan.FromMilliseconds(100))
                            .InitializeAndIsolateRepository();
            var periodicTaskRunner = container.GetInstance <PeriodicTaskRunner>();

            periodicTaskRunner.Run();

            Task.Delay(1000).Wait();
            var cache = "";

            foreach (var sendable in sender.Outbox.Cast <SendablePublicMessage>())
            {
                if (sendable.Text == cache)
                {
                    Assert.Fail();
                }
                cache = sendable.Text;
            }
        }
コード例 #6
0
        public void PeriodicTasks_YoutubeDown_DecoratorReportsErrors()
        {
            var errorableDownloadFactory = Substitute.For <IErrorableFactory <string, string, string, string> >();

            errorableDownloadFactory.Create(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>()).Returns("");
            var sender         = new TestableSerializer();
            var testableLogger = new TestableLogger();
            var container      = new TestContainerManager(c => {
                var senderRegistration = Lifestyle.Singleton.CreateRegistration(() => sender, c);
                c.RegisterConditional(typeof(IFactory <IEnumerable <ISendable <ITransmittable> >, IEnumerable <string> >), senderRegistration, _ => true);
                var errorableDownloadFactoryRegistration = Lifestyle.Singleton.CreateRegistration(() => errorableDownloadFactory, c);
                c.RegisterConditional(typeof(IErrorableFactory <string, string, string, string>), errorableDownloadFactoryRegistration, _ => true);
                var loggerRegistration = Lifestyle.Singleton.CreateRegistration(() => testableLogger, c);
                c.RegisterConditional(typeof(ILogger), loggerRegistration, pc => !pc.Handled);
            }, settings => settings.PeriodicMessageInterval = TimeSpan.FromMilliseconds(100))
                                 .InitializeAndIsolateRepository();
            var periodicTaskRunner = container.GetInstance <PeriodicTaskRunner>();

            periodicTaskRunner.Run();

            Task.Delay(900).Wait();
            Console.WriteLine(ObjectDumper.Dump(testableLogger.Outbox));
            Assert.IsTrue(testableLogger.Outbox.Any(x => x.Contains("Error occured in GenericClassFactoryTryCatchDecorator")));
            Assert.IsTrue(testableLogger.Outbox.Any(x => x.Contains("input1 is \"https://www.youtube.com/feeds/videos.xml?user=destiny\"")));
        }
コード例 #7
0
        public void Initialize()
        {
            var containerManager    = new TestContainerManager();
            var databaseInitializer = containerManager.Container.GetInstance <DatabaseInitializer>();

            databaseInitializer.Recreate();
            _container = containerManager.Container;
        }
コード例 #8
0
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
        public static void StartContainer(NodeManager nm, ContainerId cId, FileContext localFS
                                          , FilePath scriptFileDir, FilePath processStartFile)
        {
            FilePath scriptFile = CreateUnhaltingScriptFile(cId, scriptFileDir, processStartFile
                                                            );
            ContainerLaunchContext containerLaunchContext = recordFactory.NewRecordInstance <ContainerLaunchContext
                                                                                             >();
            NodeId nodeId = BuilderUtils.NewNodeId(Sharpen.Extensions.GetAddressByName("localhost"
                                                                                       ).ToString(), 12345);
            URL localResourceUri = ConverterUtils.GetYarnUrlFromPath(localFS.MakeQualified(new
                                                                                           Path(scriptFile.GetAbsolutePath())));
            LocalResource localResource = recordFactory.NewRecordInstance <LocalResource>();

            localResource.SetResource(localResourceUri);
            localResource.SetSize(-1);
            localResource.SetVisibility(LocalResourceVisibility.Application);
            localResource.SetType(LocalResourceType.File);
            localResource.SetTimestamp(scriptFile.LastModified());
            string destinationFile = "dest_file";
            IDictionary <string, LocalResource> localResources = new Dictionary <string, LocalResource
                                                                                 >();

            localResources[destinationFile] = localResource;
            containerLaunchContext.SetLocalResources(localResources);
            IList <string> commands = Arrays.AsList(Shell.GetRunScriptCommand(scriptFile));

            containerLaunchContext.SetCommands(commands);
            IPEndPoint containerManagerBindAddress = NetUtils.CreateSocketAddrForHost("127.0.0.1"
                                                                                      , 12345);
            UserGroupInformation currentUser = UserGroupInformation.CreateRemoteUser(cId.ToString
                                                                                         ());

            Org.Apache.Hadoop.Security.Token.Token <NMTokenIdentifier> nmToken = ConverterUtils
                                                                                 .ConvertFromYarn(nm.GetNMContext().GetNMTokenSecretManager().CreateNMToken(cId.GetApplicationAttemptId
                                                                                                                                                                (), nodeId, user), containerManagerBindAddress);
            currentUser.AddToken(nmToken);
            ContainerManagementProtocol containerManager = currentUser.DoAs(new _PrivilegedAction_229
                                                                                ());
            StartContainerRequest scRequest = StartContainerRequest.NewInstance(containerLaunchContext
                                                                                , TestContainerManager.CreateContainerToken(cId, 0, nodeId, user, nm.GetNMContext
                                                                                                                                ().GetContainerTokenSecretManager()));
            IList <StartContainerRequest> list = new AList <StartContainerRequest>();

            list.AddItem(scRequest);
            StartContainersRequest allRequests = StartContainersRequest.NewInstance(list);

            containerManager.StartContainers(allRequests);
            IList <ContainerId> containerIds = new AList <ContainerId>();

            containerIds.AddItem(cId);
            GetContainerStatusesRequest request = GetContainerStatusesRequest.NewInstance(containerIds
                                                                                          );
            ContainerStatus containerStatus = containerManager.GetContainerStatuses(request).
                                              GetContainerStatuses()[0];

            NUnit.Framework.Assert.AreEqual(ContainerState.Running, containerStatus.GetState(
                                                ));
        }
コード例 #9
0
        public void DownloadMapper_OverRustleLogsNonexistantUser_404s_DoNotRunContinuously()
        {
            var testContainerManager = new TestContainerManager();
            var downloadFactory      = testContainerManager.Container.GetInstance <IDownloadMapper>();

            var exception = TestHelper.AssertCatch <WebException>(() => downloadFactory.OverRustleLogs(TestHelper.RandomString()));

            Assert.AreEqual(((HttpWebResponse)exception.Response).StatusCode, HttpStatusCode.NotFound);
        }
コード例 #10
0
        public void InitialUsers_ParsesPublicMessages_WithCorrectTimestamp()
        {
            var data      = TestData.DestinyGgPublicMsg;
            var container = new TestContainerManager();
            var parser    = container.Container.GetInstance <DestinyGgParser>();
            var timestamp = parser.Create(data).Timestamp;

            Assert.AreEqual(new DateTime(2017, 5, 9, 0, 28, 35, 517), timestamp);
        }
コード例 #11
0
        public void InitialUsers_ParsesPublicMessagesFromMod_AsMod()
        {
            var data      = TestData.DestinyGgPublicMsgFromMod;
            var container = new TestContainerManager();
            var parser    = container.Container.GetInstance <DestinyGgParser>();
            var received  = parser.Create(data);

            Assert.IsTrue(received.Sender.IsMod);
        }
コード例 #12
0
        public void InitialUsers_ParsesPublicMessagesFromProtected_AsNonpunishable()
        {
            var data      = TestData.DestinyGgPublicMsgFromProtected;
            var container = new TestContainerManager();
            var parser    = container.Container.GetInstance <DestinyGgParser>();
            var received  = parser.Create(data);

            Assert.IsFalse(received.Sender.IsPunishable);
        }
コード例 #13
0
        public void CustomCommandsRepository_GetAll_ReturnsMasterData()
        {
            var container  = new TestContainerManager().InitializeAndIsolateRepository();
            var repository = container.GetInstance <IQueryCommandService <IUnitOfWork> >();

            var customCommands = repository.Query(r => r.CustomCommand.GetAll);

            Assert.IsTrue(customCommands.Single(c => c.Command == "rules").Response == "github.com/destinygg/bot2");
        }
コード例 #14
0
        public void DownloadMapper_OverRustleLogsExistingUser_DoesNotCrash_DoNotRunContinuously()
        {
            var testContainerManager = new TestContainerManager();
            var downloadMapper       = testContainerManager.Container.GetInstance <IDownloadMapper>();

            var logs = downloadMapper.OverRustleLogs("woopboop");

            Assert.IsNotNull(logs);
        }
コード例 #15
0
ファイル: TwitterTests.cs プロジェクト: PunishedJohbi/bot2
        public void TwitterManager_LatestTweetFromDestiny_RequiresManualCheckingForReasonablewResult_DoNotRunContinuously()
        {
            var container      = new TestContainerManager().InitializeAndIsolateRepository();
            var twitterManager = container.GetInstance <ITwitterManager>();

            var latest = twitterManager.LatestTweetFromDestiny(true);

            Console.WriteLine(ObjectDumper.Dump(latest));
        }
コード例 #16
0
        public void CustomCommandsRepository_GetNonexistantCommand_ReturnsNull()
        {
            var container          = new TestContainerManager().InitializeAndIsolateRepository();
            var repository         = container.GetInstance <IQueryCommandService <IUnitOfWork> >();
            var nonexistantCommand = TestHelper.RandomString();

            var customCommand = repository.Query(r => r.CustomCommand.Get(nonexistantCommand));

            Assert.IsNull(customCommand);
        }
コード例 #17
0
        public void ErrorableDownloadFactory_Real404_ReturnsErrorText_DoNotRunContinuously()
        {
            var testContainerManager     = new TestContainerManager();
            var errorableDownloadFactory = testContainerManager.Container.GetInstance <IErrorableFactory <string, string, string, string> >();
            var errorText = Guid.NewGuid().ToString();

            var html = errorableDownloadFactory.Create("https://httpbin.org/404", "", errorText);

            Assert.AreEqual(errorText, html);
        }
コード例 #18
0
        public void ErrorableDownloadFactory_PlainCreate_Works_DoNotRunContinuously()
        {
            var testContainerManager     = new TestContainerManager();
            var errorableDownloadFactory = testContainerManager.Container.GetInstance <IErrorableFactory <string, string, string, string> >();

            var html = errorableDownloadFactory.Create("https://httpbin.org/html", "", "");

            var expectedHtml = "<!DOCTYPE html>\n<html>\n  <head>\n  </head>\n  <body>\n      <h1>Herman Melville - Moby-Dick</h1>\n\n      <div>\n        <p>\n          Availing himself of the mild, summer-cool weather that now reigned in these latitudes, and in preparation for the peculiarly active pursuits shortly to be anticipated, Perth, the begrimed, blistered old blacksmith, had not removed his portable forge to the hold again, after concluding his contributory work for Ahab's leg, but still retained it on deck, fast lashed to ringbolts by the foremast; being now almost incessantly invoked by the headsmen, and harpooneers, and bowsmen to do some little job for them; altering, or repairing, or new shaping their various weapons and boat furniture. Often he would be surrounded by an eager circle, all waiting to be served; holding boat-spades, pike-heads, harpoons, and lances, and jealously watching his every sooty movement, as he toiled. Nevertheless, this old man's was a patient hammer wielded by a patient arm. No murmur, no impatience, no petulance did come from him. Silent, slow, and solemn; bowing over still further his chronically broken back, he toiled away, as if toil were life itself, and the heavy beating of his hammer the heavy beating of his heart. And so it was.—Most miserable! A peculiar walk in this old man, a certain slight but painful appearing yawing in his gait, had at an early period of the voyage excited the curiosity of the mariners. And to the importunity of their persisted questionings he had finally given in; and so it came to pass that every one now knew the shameful story of his wretched fate. Belated, and not innocently, one bitter winter's midnight, on the road running between two country towns, the blacksmith half-stupidly felt the deadly numbness stealing over him, and sought refuge in a leaning, dilapidated barn. The issue was, the loss of the extremities of both feet. Out of this revelation, part by part, at last came out the four acts of the gladness, and the one long, and as yet uncatastrophied fifth act of the grief of his life's drama. He was an old man, who, at the age of nearly sixty, had postponedly encountered that thing in sorrow's technicals called ruin. He had been an artisan of famed excellence, and with plenty to do; owned a house and garden; embraced a youthful, daughter-like, loving wife, and three blithe, ruddy children; every Sunday went to a cheerful-looking church, planted in a grove. But one night, under cover of darkness, and further concealed in a most cunning disguisement, a desperate burglar slid into his happy home, and robbed them all of everything. And darker yet to tell, the blacksmith himself did ignorantly conduct this burglar into his family's heart. It was the Bottle Conjuror! Upon the opening of that fatal cork, forth flew the fiend, and shrivelled up his home. Now, for prudent, most wise, and economic reasons, the blacksmith's shop was in the basement of his dwelling, but with a separate entrance to it; so that always had the young and loving healthy wife listened with no unhappy nervousness, but with vigorous pleasure, to the stout ringing of her young-armed old husband's hammer; whose reverberations, muffled by passing through the floors and walls, came up to her, not unsweetly, in her nursery; and so, to stout Labor's iron lullaby, the blacksmith's infants were rocked to slumber. Oh, woe on woe! Oh, Death, why canst thou not sometimes be timely? Hadst thou taken this old blacksmith to thyself ere his full ruin came upon him, then had the young widow had a delicious grief, and her orphans a truly venerable, legendary sire to dream of in their after years; and all of them a care-killing competency.\n        </p>\n      </div>\n  </body>\n</html>";

            Assert.AreEqual(expectedHtml, html);
        }
コード例 #19
0
        public void DestinyGgSerializer_IpbanSomeDuration_ParsesProperly()
        {
            var container           = new TestContainerManager().Container;
            var sendableBan         = new SendableIpban(new Civilian("User"), TimeSpan.FromSeconds(1));
            var destinyGgSerializer = container.GetInstance <DestinyGgSerializer>();
            var expected            = @"BAN {""Nick"":""User"",""Duration"":1000000000,""BanIp"":true,""Reason"":""Unspecified reason""}";

            var serialized = destinyGgSerializer.Create(sendableBan.Wrap().ToList());

            Assert.AreEqual(expected, serialized.Single());
        }
コード例 #20
0
        public void StreamStatusServiceProvider_Get_ReturnsTheSameInstance()
        {
            // Uses the CachedProviderDecorator
            var container = new TestContainerManager().InitializeAndIsolateRepository();
            var streamStateServiceProvider = container.GetInstance <IProvider <IStreamStateService> >();

            var objA = streamStateServiceProvider.Get();
            var objB = streamStateServiceProvider.Get();

            Assert.IsTrue(ReferenceEquals(objA, objB));
        }
コード例 #21
0
        public void DestinyGgSerializer_BanMaxDuration_ParsesProperly()
        {
            var container           = new TestContainerManager().Container;
            var sendableBan         = new SendableBan(new Civilian("User"), TimeSpan.MaxValue);
            var destinyGgSerializer = container.GetInstance <DestinyGgSerializer>();
            var expected            = @"BAN {""Nick"":""User"",""IsPermanent"":true,""Reason"":""Unspecified reason""}";

            var serialized = destinyGgSerializer.Create(sendableBan.Wrap().ToList());

            Assert.AreEqual(expected, serialized.Single());
        }
コード例 #22
0
        public void Log4NetLogger_Displays_TryCatchFactoryExceptions()
        {
            XmlConfigurator.Configure(new FileInfo(@"log4net.config"));
            var containerManager = new TestContainerManager();
            var errorableFactory = containerManager.Container.GetInstance <IErrorableFactory <ISnapshot <Moderator, IMessage>, IReadOnlyList <ISendable <ITransmittable> > > >();
            var receivedFactory  = containerManager.Container.GetInstance <ReceivedFactory>();
            var snapshotFactory  = containerManager.Container.GetInstance <SnapshotFactory>();
            var snapshot         = snapshotFactory.Create(receivedFactory.ModPublicReceivedMessage("derp"));

            errorableFactory.Create((ISnapshot <Moderator, PublicMessage>)snapshot);
        }
コード例 #23
0
        private Container CreateContainer(TestableSerializer sender)
        {
            var containerManager = new TestContainerManager(container => {
                var senderRegistration = Lifestyle.Singleton.CreateRegistration(() => sender, container);
                container.RegisterConditional(typeof(IFactory <IEnumerable <ISendable <ITransmittable> >, IEnumerable <string> >),
                                              senderRegistration, _ => true);
            }, settings => {
                settings.CivilianCommandInterval = TimeSpan.FromSeconds(0);
            }).InitializeAndIsolateRepository();

            return(containerManager);
        }
コード例 #24
0
ファイル: NukeHelper.cs プロジェクト: PunishedJohbi/bot2
        public static Container GetContainer(ITimeService timeService, ISettings settings)
        {
            var containerManager = new TestContainerManager(
                container => {
                var timeServiceRegistration = Lifestyle.Singleton.CreateRegistration(() => timeService, container);
                container.RegisterConditional(typeof(ITimeService), timeServiceRegistration, pc => !pc.Handled);
                var settingsServiceRegistration = Lifestyle.Singleton.CreateRegistration(() => settings, container);
                container.RegisterConditional(typeof(ISettings), settingsServiceRegistration, pc => !pc.Handled);
            });

            return(containerManager.Container);
        }
コード例 #25
0
        public void DestinyGgSerializer_SingleMessage_IsNotModified()
        {
            var text                = "and here, we... go";
            var container           = new TestContainerManager().Container;
            var message             = new SendablePublicMessage(text);
            var destinyGgSerializer = container.GetInstance <DestinyGgSerializer>();
            var expected            = @"MSG {""Data"":""and here, we... go""}";

            var serialized = destinyGgSerializer.Create(message.Wrap().ToList());

            Assert.AreEqual(expected, serialized.Single());
        }
コード例 #26
0
        public void SingleLineSpamPunishmentFactory_MinimumRepeat_DoesNotPunish()
        {
            var minimumRepeatLength = 3;
            var text      = "aaa";
            var container = new TestContainerManager(configureSettings: s => s.RepeatCharacterSpamLimit = minimumRepeatLength).Container;
            var selfSpamPunishmentFactory = container.GetInstance <SingleLineSpamPunishmentFactory>();
            var receivedFactory           = container.GetInstance <ReceivedFactory>();
            var snapshot = receivedFactory.PublicReceivedSnapshot(text);

            var bans = selfSpamPunishmentFactory.Create(snapshot);

            Assert.IsFalse(bans.Any());
        }
コード例 #27
0
        public void ModCommandRepositoryLogic_DelMuteWithEmptyDb_YieldsEmptyDb()
        {
            var mutedPhrase          = "words are wind";
            var testContainerManager = new TestContainerManager().InitializeAndIsolateRepository();
            var modCommandLogic      = testContainerManager.GetInstance <IModCommandRepositoryLogic>();
            var unitOfWork           = testContainerManager.GetInstance <IQueryCommandService <IUnitOfWork> >();

            modCommandLogic.DelMute(mutedPhrase);

            var autoPunishments = unitOfWork.Query(u => u.AutoPunishments.GetAllWithUser);

            Assert.IsFalse(autoPunishments.Any());
        }
コード例 #28
0
        public void ModCommandRepositoryLogic_DelMuteWithEmptyDb_IsNotInTheAutomuteList()
        {
            var mutedPhrase          = "words are wind";
            var expectedMessage      = $"{mutedPhrase} is not in the automute list";
            var testContainerManager = new TestContainerManager().InitializeAndIsolateRepository();
            var modCommandLogic      = testContainerManager.GetInstance <IModCommandRepositoryLogic>();

            var sendables = modCommandLogic.DelMute(mutedPhrase);

            var actualMessage = sendables.Cast <SendablePublicMessage>().Single().Text;

            Assert.AreEqual(expectedMessage, actualMessage);
        }
コード例 #29
0
        public void CustomCommandsRepository_AddTwice_ThrowsConstraintFailedException()
        {
            var container  = new TestContainerManager().InitializeAndIsolateRepository();
            var command    = TestHelper.RandomString();
            var response   = TestHelper.RandomString();
            var repository = container.GetInstance <IQueryCommandService <IUnitOfWork> >();

            repository.Command(r => r.CustomCommand.Add(command, response));

            var exception = TestHelper.AssertCatch <DbUpdateException>(() => repository.Command(r => r.CustomCommand.Add(command, response)));

            Assert.IsTrue(exception.InnerException.Message.Contains("SQLite Error 19"));
        }
コード例 #30
0
        public void InitialUsers_ParsesMods_Properly()
        {
            var data          = TestData.DestinyGgClientNames;
            var container     = new TestContainerManager();
            var parser        = container.Container.GetInstance <DestinyGgParser>();
            var received      = parser.Create(data);
            var initialUsers  = (InitialUsers)received.Transmission;
            var notPunishable = initialUsers.Users.Where(x => x.IsMod).Select(x => x.Nick);

            Assert.IsTrue(notPunishable.SequenceEqual(new List <string> {
                "RightToBearArmsLOL", "CeneZa", "Destiny", "Bot"
            }));
        }