public async Task Return_all_the_content_that_exists() { // arrange var request = new StaticCommandsLookup(); var commands = new ValidStaticCommands { Commands = new List <StaticCommandInfo> { new StaticCommandInfo { Command = "foo", Content = "bar" }, new StaticCommandInfo { Command = "foo2", Content = "bar2" }, } }; MockCollection.Setup(x => x.GetAsync("staticContentCommands", null)) .ReturnsAsync(new FakeGetResult(commands)); // act var result = await _handler.Handle(request, CancellationToken.None); // assert Assert.That(result, Is.Not.Null); Assert.That(result.Commands, Is.Not.Null); Assert.That(result.Commands.Any(), Is.True); Assert.That(result.Commands.Count, Is.EqualTo(commands.Commands.Count)); }
public void Setup() { UnityEngine.Assertions.Assert.raiseExceptions = true; _identity1 = new Identity() { owner = 1 }; _identity2 = new Identity() { owner = 2 }; _identity3 = new Identity() { owner = 3 }; _collection1 = new MockCollection() { ID = System.Guid.NewGuid(), collectionName = "Collection1", owner = _identity1 }; _collection2 = new MockCollection() { ID = System.Guid.NewGuid(), collectionName = "Collection2", owner = _identity1 }; _collection3 = new MockCollection() { ID = System.Guid.NewGuid(), collectionName = "Collection3", owner = _identity1 }; _permissions = new NetworkPermissionsMap <MockCollection, Identity>(); }
public async Task Send_farfare_notice_when_user_has_fanfare_and_is_arriving(bool hasFanfare, int timesSent) { // arrange var username = "******"; var expectedFanfare = new FanfareInfo { Message = "message " + Guid.NewGuid(), Timeout = 12312, YouTubeCode = "ytcode" + Guid.NewGuid(), YouTubeStartTime = 111, YouTubeEndTime = 222 }; var twitchLibMessage = TwitchLibMessageBuilder.Create().WithUsername(username).Build(); var chatMessage = ChatMessageBuilder.Create().WithTwitchLibMessage(twitchLibMessage).Build(); var request = new UserHasArrived(chatMessage); MockCollection.Setup(x => x.ExistsAsync($"{username}::arrived_recently", null)) .ReturnsAsync(new FakeExistsResult(false)); MockCollection.Setup(x => x.GetAsync(It.IsAny <string>(), null)) .ReturnsAsync(new FakeGetResult(new TwitcherProfile { HasFanfare = hasFanfare, Fanfare = expectedFanfare })); // act await _handler.Handle(request, CancellationToken.None); // assert _mockTwitchHub.Verify(x => x.ReceiveFanfare(expectedFanfare), Times.Exactly(timesSent)); }
public async Task ShoutOut_WILL_shout_if_the_given_username_is_a_real_twitch_user() { // arrange var userLookup = "doesntmattereither"; var twitchLibMessage = TwitchLibMessageBuilder.Create() .WithUsername("doesntmatter") .Build(); var chatMessage = ChatMessageBuilder.Create() .WithTwitchLibMessage(twitchLibMessage) .WithIsSubscriber(true) .WithMessage($"!so {userLookup}") .Build(); MockApiWrapper.Setup(x => x.DoesUserExist(userLookup)).ReturnsAsync(true); MockCollection.Setup(x => x.ExistsAsync(userLookup.ToLower(), null)) .ReturnsAsync(new FakeExistsResult(true)); MockCollection.Setup(x => x.GetAsync(userLookup.ToLower(), null)) .ReturnsAsync(new FakeGetResult(new TwitcherProfile())); var shout = new ShoutOut(chatMessage); // act await _handler.Handle(shout, CancellationToken.None); // assert MockTwitchClient.Verify(x => x.SendMessage(It.IsAny <string>(), It.IsAny <string>(), false), Times.Once); }
public async Task ShoutOut_is_limited_to_mods_and_subs(bool isSub, bool isMod, int numVerified) { // arrange var userToShout = "someusername"; var twitchLibMessage = TwitchLibMessageBuilder.Create() .WithUsername("NonSub") .Build(); var chatMessage = ChatMessageBuilder.Create() .WithTwitchLibMessage(twitchLibMessage) .WithMessage($"!so {userToShout}") .WithIsSubscriber(isSub) .WithIsModerator(isMod) .Build(); var request = new ShoutOut(chatMessage); MockApiWrapper.Setup(m => m.DoesUserExist(It.IsAny <string>())).ReturnsAsync(true); MockCollection.Setup(m => m.ExistsAsync(userToShout, null)) .ReturnsAsync(new FakeExistsResult(true)); MockCollection.Setup(m => m.GetAsync(userToShout, null)) .ReturnsAsync(new FakeGetResult(new TwitcherProfile())); // act await _handler.Handle(request, CancellationToken.None); // assert MockTwitchClient.Verify(x => x.SendMessage(It.IsAny <string>(), It.IsAny <string>(), false), Times.Exactly(numVerified)); }
public async Task ShoutOut_will_use_custom_message_if_there_is_one() { // arrange var userProfile = new TwitcherProfile { ShoutMessage = "hey hey look at me" + Guid.NewGuid() }; var userName = "******"; var expectedShoutMessage = userProfile.ShoutMessage + $" https://twitch.tv/{userName}"; var twitchLibMessage = TwitchLibMessageBuilder.Create() .WithUsername("doesntmatter") .Build(); var chatMessage = ChatMessageBuilder.Create() .WithTwitchLibMessage(twitchLibMessage) .WithIsSubscriber(true) .WithMessage($"!so {userName}") .Build(); MockApiWrapper.Setup(x => x.DoesUserExist(userName)).ReturnsAsync(true); MockCollection.Setup(x => x.ExistsAsync(userName.ToLower(), null)) .ReturnsAsync(new FakeExistsResult(true)); MockCollection.Setup(x => x.GetAsync(userName.ToLower(), null)) .ReturnsAsync(new FakeGetResult(userProfile)); var shout = new ShoutOut(chatMessage); // act await _handler.Handle(shout, CancellationToken.None); // assert MockTwitchClient.Verify(x => x.SendMessage(It.IsAny <string>(), expectedShoutMessage, false), Times.Once); }
public async Task Should_insert_message_into_bucket() { // arrange var expectedUsername = "******" + Guid.NewGuid(); var expectedMessage = "some message whatever " + Guid.NewGuid(); var expectedChannel = "mychannel" + Guid.NewGuid(); var twitchLibMessage = TwitchLibMessageBuilder.Create() .WithUsername(expectedUsername) .Build(); var chatMessage = ChatMessageBuilder.Create() .WithTwitchLibMessage(twitchLibMessage) .WithMessage(expectedMessage) .WithChannel(expectedChannel) .Build(); var request = new StoreMessage(chatMessage); // act await _handler.Handle(request, CancellationToken.None); // assert MockCollection.Verify(x => x.InsertAsync(It.IsAny <string>(), It.IsAny <ChatMessage>(), null), Times.Once()); MockCollection.Verify(x => x.InsertAsync(It.IsAny <string>(), It.Is <ChatMessage>(d => d.Username == expectedUsername), null), Times.Once()); MockCollection.Verify(x => x.InsertAsync(It.IsAny <string>(), It.Is <ChatMessage>(d => d.Message == expectedMessage), null), Times.Once()); MockCollection.Verify(x => x.InsertAsync(It.IsAny <string>(), It.Is <ChatMessage>(d => d.Channel == expectedChannel), null), Times.Once()); }
public void _0006() { var persons = new MockCollection(); var th1 = new Thread(new ThreadStart(() => { for (var i = 1; i < 100; i++) { persons.Add(new PersonItem("Homer", "Simpson")); lock ((persons as ICollection).SyncRoot){ Thread.Sleep(200); } } })); var th2 = new Thread(new ThreadStart(() => { for (var i = 1; i < 100; i++) { lock ((persons as ICollection).SyncRoot){ persons.Add(new PersonItem("Bart", "Simpson")); Thread.Sleep(50); } } })); th1.Start(); th2.Start(); th1.Join(); th2.Join(); //Homer //Bart //Homer //Bart //Homer //Bart }
public async Task ShoutOut_will_shout_the_given_username() { // arrange var userName = "******"; var twitchLibMessage = TwitchLibMessageBuilder.Create() .WithUsername("doesntmatter") .Build(); var chatMessage = ChatMessageBuilder.Create() .WithTwitchLibMessage(twitchLibMessage) .WithIsSubscriber(true) .WithMessage($"!so {userName}") .Build(); MockApiWrapper.Setup(x => x.DoesUserExist(userName)).ReturnsAsync(true); MockCollection.Setup(x => x.ExistsAsync(userName.ToLower(), null)) .ReturnsAsync(new FakeExistsResult(true)); MockCollection.Setup(x => x.GetAsync(userName.ToLower(), null)) .ReturnsAsync(new FakeGetResult(new TwitcherProfile())); var shout = new ShoutOut(chatMessage); var expectedMessage = $"Hey everyone, check out @{userName}'s Twitch stream at https://twitch.tv/{userName}"; // act await _handler.Handle(shout, CancellationToken.None); // assert MockTwitchClient.Verify(x => x.SendMessage(It.IsAny <string>(), expectedMessage, false), Times.Once); }
public async Task Returns_valid_sound_effects() { // arrange var validSoundEffects = new ValidSoundEffects { SoundEffects = new List <SoundEffectInfo> { new SoundEffectInfo { SoundEffectName = "woof" + Guid.NewGuid() }, new SoundEffectInfo { SoundEffectName = "meow" + Guid.NewGuid() }, new SoundEffectInfo { SoundEffectName = "carcrash" + Guid.NewGuid() } } }; var request = new SoundEffectLookup(); MockCollection.Setup(x => x.GetAsync("validSoundEffects", null)) .ReturnsAsync(new FakeGetResult(validSoundEffects)); // act var result = await _handler.Handle(request, CancellationToken.None); // assert Assert.That(result.SoundEffects, Is.Not.Null); Assert.That(result.SoundEffects, Is.Not.Empty); Assert.That(result.SoundEffects.Count, Is.EqualTo(validSoundEffects.SoundEffects.Count)); foreach (var effect in validSoundEffects.SoundEffects) { Assert.That(result.SoundEffects.Any(x => x.SoundEffectName == effect.SoundEffectName), Is.True); } }
public async Task Gets_content_and_says_it_to_chat_room() { // arrange var channel = "somechannel" + Guid.NewGuid(); var commandName = "!somemessage"; var expectedContent = "blah blah blah whatever " + Guid.NewGuid(); var content = new ValidStaticCommands { Commands = new List <StaticCommandInfo> { new StaticCommandInfo { Command = commandName, Content = expectedContent } } }; MockCollection.Setup(x => x.GetAsync("staticContentCommands", null)) .ReturnsAsync(new FakeGetResult(content)); var request = new StaticMessage(commandName, channel); // act await _handler.Handle(request, CancellationToken.None); // assert // _twitchClient.SendMessage(request.Channel, command.Content); MockTwitchClient.Verify(x => x.SendMessage(channel, expectedContent, false), Times.Once); }
public async Task Show_current_project_url() { // arrange var expectedUrl = "http://example.org/foo/bar"; var expectedMessage = $"Current Project is: " + expectedUrl; var projectInfo = new CurrentProjectInfo { Url = new Uri(expectedUrl) }; var twitchLibMessage = TwitchLibMessageBuilder.Create() .WithUsername("doesntmatterusername") .Build(); var chatMessage = ChatMessageBuilder.Create() .WithTwitchLibMessage(twitchLibMessage) .WithMessage("!currentproject") .WithChannel("doesntmatterchannel") .Build(); var request = new SayCurrentProject(chatMessage); MockCollection.Setup(x => x.GetAsync("currentProject", null)) .ReturnsAsync(new FakeGetResult(projectInfo)); // act await _handler.Handle(request, CancellationToken.None); // assert MockTwitchClient.Verify(x => x.SendMessage(It.IsAny <string>(), expectedMessage, false), Times.Once); }
public async Task Create_recent_activity_marker_document_if_necessary() { // arrange var username = "******"; MockCollection.Setup(x => x.ExistsAsync($"{username}::arrived_recently", null)) .ReturnsAsync(new FakeExistsResult(false)); var twitchLibMessage = TwitchLibMessageBuilder.Create().WithUsername(username).Build(); var chatMessage = ChatMessageBuilder.Create().WithTwitchLibMessage(twitchLibMessage).Build(); var request = new UserHasArrived(chatMessage); MockCollection.Setup(x => x.GetAsync(It.IsAny <string>(), null)) .ReturnsAsync(new FakeGetResult(new TwitcherProfile())); _mockTwitchHub.Setup(x => x.ReceiveFanfare(It.IsAny <FanfareInfo>())); // act await _handler.Handle(request, CancellationToken.None); // assert MockCollection.Verify(x => x.UpsertAsync( It.Is <string>(k => k == $"{username}::arrived_recently"), It.IsAny <UserHasArrivedMarker>(), It.IsAny <UpsertOptions>()), Times.Once); MockCollection.Verify(x => x.UpsertAsync( It.IsAny <string>(), It.IsAny <UserHasArrivedMarker>(), It.Is <UpsertOptions>(u => (u.GetInternalPropertyValue <TimeSpan, UpsertOptions>("ExpiryValue")).Hours == 12)), Times.Once); }
public UnitTestStartup( IConfiguration configuration, IHostingEnvironment hostingEnvironment, MockCollection mockCollection) : base(configuration, hostingEnvironment) { _mockCollection = mockCollection; }
public void TestCollectionHandler() { Serializer s = new Serializer("TestCollectionHandlers"); MockCollection coll = new MockCollection("test"); string result = s.Serialize(coll); MockCollection actual = s.Deserialize <MockCollection>(result); Assert.AreEqual(coll.Value(), actual.Value(), "MockCollectionHandler not configured correctly"); }
public async Task If_homePageInfo_document_doesnt_exist_return_empty_object() { // arrange MockCollection.Setup(m => m.ExistsAsync(It.IsAny <string>(), null)) .ReturnsAsync(new FakeExistsResult(false)); // act var result = await _handler.Handle(new GetHomePageInfo(), CancellationToken.None); // assert Assert.That(result, Is.Not.Null); Assert.That(result.Badges, Is.Null); }
public async Task If_profile_does_exist_then_upsert_doesnt_happen() { // arrange var username = "******"; var request = new CreateProfileIfNotExists(username); MockCollection.Setup(m => m.ExistsAsync(username, null)).ReturnsAsync(new FakeExistsResult(true)); // act await _handler.Handle(request, CancellationToken.None); // assert MockCollection.Verify(m => m.UpsertAsync(It.IsAny <string>(), It.IsAny <TwitcherProfile>(), null), Times.Never); }
public ActionResult Execute(string text) { var collection = new MockCollection(text); var mocks = collection.Get(); List <MockModel> result = new List <MockModel>(); foreach (var mock in mocks) { var m = mock.Get(); var executor = new MockExecutor(m); result = executor.PerformAction(); } return(JsonSuccess(result)); }
public async Task If_homePageInfo_retrieve_fails_then_return_empty_object() { // arrange MockCollection.Setup(m => m.ExistsAsync(It.IsAny <string>(), null)).ReturnsAsync(new FakeExistsResult(true)); MockCollection.Setup(m => m.GetAsync(It.IsAny <string>(), null)) .Throws(new Exception("retrieve fails")); // act var result = await _handler.Handle(new GetHomePageInfo(), CancellationToken.None); // assert Assert.That(result, Is.Not.Null); Assert.That(result.Badges, Is.Null); }
public async Task Return_empty_list_if_there_are_no_commands_stored_in_database() { // arrange var request = new StaticCommandsLookup(); MockCollection.Setup(x => x.GetAsync("staticContentCommands", null)) .Throws <Exception>(); // act var result = await _handler.Handle(request, CancellationToken.None); // assert Assert.That(result, Is.Not.Null); Assert.That(result.Commands == null || !result.Commands.Any(), Is.True); }
public async Task Profile_is_looked_up_by_twitch_username() { // arrange var username = "******"; var request = new GetProfile(username); MockCollection.Setup(m => m.GetAsync(It.IsAny <string>(), null)) .ReturnsAsync(new FakeGetResult(new TwitcherProfile())); // act await _handler.Handle(request, CancellationToken.None); // assert MockCollection.Verify(m => m.GetAsync(username, It.IsAny <GetOptions>()), Times.Once); }
public async Task Returns_no_valid_sound_effects_if_validSoundEffects_data_doesnt_exist() { // arrange var request = new SoundEffectLookup(); MockCollection.Setup(x => x.GetAsync("validSoundEffects", null)) .Throws <Exception>(); // act var result = await _handler.Handle(request, CancellationToken.None); // assert Assert.That(result, Is.Not.Null); Assert.That(result.SoundEffects == null || !result.SoundEffects.Any(), Is.True); }
public ActionResult ExecuteVoice(string fileName) { var filePath = Path.Combine(Path.GetDirectoryName(MockApp.tdb), fileName); using (var fs = new FileStream(filePath, FileMode.Open)) { var collection = new MockCollection(fs); var mocks = collection.Get(); List <MockModel> result = new List <MockModel>(); foreach (var mock in mocks) { var m = mock.Get(); var executor = new MockExecutor(m); result = executor.PerformAction(); } return(JsonSuccess(result)); } }
public async Task Return_homePageInfo_from_database() { // arrange var info = new HomePageInfo(); info.Badges = new List <SocialMediaBadge>(); info.Badges.Add(new SocialMediaBadge { Icon = "foo", Text = "bar" }); MockCollection.Setup(m => m.ExistsAsync(It.IsAny <string>(), null)).ReturnsAsync(new FakeExistsResult(true)); MockCollection.Setup(m => m.GetAsync(It.IsAny <string>(), null)) .ReturnsAsync(new FakeGetResult(info)); // act var result = await _handler.Handle(new GetHomePageInfo(), CancellationToken.None); // assert Assert.That(result, Is.Not.Null); Assert.That(result, Is.EqualTo(info)); }
public async Task Says_okay_if_able_to_store() { // arrange var twitchLibMessage = TwitchLibMessageBuilder.Create() .WithUsername(MockTwitchOptions.Object.Value.Username) .Build(); var chatMessage = ChatMessageBuilder.Create() .WithTwitchLibMessage(twitchLibMessage) .WithMessage("!setcurrentproject http://validurl.com") .Build(); var request = new SetCurrentProject(chatMessage); MockCollection.Setup(x => x.UpsertAsync(It.IsAny <string>(), It.IsAny <CurrentProjectInfo>(), null)) .ReturnsAsync(new FakeMutationResult()); // act await _handler.Handle(request, CancellationToken.None); // assert MockTwitchClient.Verify(x => x.SendMessage(It.IsAny <string>(), "Okay, got it!", false), Times.Once); }
public async Task Says_an_error_message_if_unable_to_store() { // arrange var twitchLibMessage = TwitchLibMessageBuilder.Create() .WithUsername(MockTwitchOptions.Object.Value.Username) .Build(); var chatMessage = ChatMessageBuilder.Create() .WithTwitchLibMessage(twitchLibMessage) .WithMessage("!setcurrentproject http://validurl.com") .Build(); var request = new SetCurrentProject(chatMessage); MockCollection.Setup(x => x.UpsertAsync(It.IsAny <string>(), It.IsAny <CurrentProjectInfo>(), null)) .Throws <Exception>(); // act await _handler.Handle(request, CancellationToken.None); // assert MockTwitchClient.Verify(x => x.SendMessage(It.IsAny <string>(), "I was unable to store that, sorry!", false), Times.Once); }
public async Task Should_not_create_a_profile_if_one_already_exists() { // arrange var username = "******"; var twitchLibMessage = TwitchLibMessageBuilder.Create() .WithUsername(username) .Build(); var chatMessage = ChatMessageBuilder.Create() .WithTwitchLibMessage(twitchLibMessage) .WithMessage("notnull") .Build(); var request = new ModifyProfile(chatMessage); MockCollection.Setup(x => x.ExistsAsync(username, null)) .ReturnsAsync(new FakeExistsResult(true)); // act await _handler.Handle(request, CancellationToken.None); // assert MockCollection.Verify(x => x.InsertAsync(username, It.IsAny <TwitcherProfile>(), null), Times.Never); }
public async Task No_fanfare_if_there_is_no_user_profile() { // arrange var username = "******"; var twitchLibMessage = TwitchLibMessageBuilder.Create().WithUsername(username).Build(); var chatMessage = ChatMessageBuilder.Create().WithTwitchLibMessage(twitchLibMessage).Build(); var request = new UserHasArrived(chatMessage); // setup: user has NOT arrive recently MockCollection.Setup(m => m.ExistsAsync($"{username}::arrived_recently", null)) .ReturnsAsync(new FakeExistsResult(false)); // setup: don't care about the arrive_recently document being added MockCollection.Setup(m => m.UpsertAsync(It.IsAny <string>(), It.IsAny <UserHasArrivedMarker>(), null)); // setup: user does NOT have a profile MockCollection.Setup(m => m.GetAsync(username.ToLower(), null)) .ReturnsAsync(new FakeGetResult(null)); // act await _handler.Handle(request, CancellationToken.None); // assert _mockTwitchHub.Verify(m => m.ReceiveFanfare(It.IsAny <FanfareInfo>()), Times.Never); }
public async Task Only_the_bot_user_itself_can_set_the_current_project() { // arrange var notTheBotUser = MockTwitchOptions.Object.Value.Username + Guid.NewGuid(); var twitchLibMessage = TwitchLibMessageBuilder.Create() .WithUsername(notTheBotUser) .Build(); var chatMessage = ChatMessageBuilder.Create() .WithTwitchLibMessage(twitchLibMessage) .WithMessage("doesntmatter") .Build(); var request = new SetCurrentProject(chatMessage); // act await _handler.Handle(request, CancellationToken.None); // assert - twitch client never used, bucket never used MockTwitchClient.Verify(x => x.SendMessage(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <bool>()), Times.Never); MockCollection.Verify(x => x.UpsertAsync(It.IsAny <string>(), It.IsAny <CurrentProjectInfo>(), null), Times.Never); }
public async Task Should_create_a_profile_if_one_doesnt_exist() { // arrange var username = "******"; var twitchLibMessage = TwitchLibMessageBuilder.Create() .WithUsername(username) .Build(); var chatMessage = ChatMessageBuilder.Create() .WithTwitchLibMessage(twitchLibMessage) .WithMessage("doesntmatter") .Build(); var request = new ModifyProfile(chatMessage); MockCollection.Setup(m => m.ExistsAsync(username, null)) .ReturnsAsync(new FakeExistsResult(false)); // act await _handler.Handle(request, CancellationToken.None); // assert MockCollection.Verify(x => x.InsertAsync(username, It.Is <TwitcherProfile>( y => y.Type == "profile"), null), Times.Once); }