public void TestGetMessage_ShouldGetTheMessageText() { var options = TestHelper.optionsFactory("add_artist_db"); using (var context = new MusichinoDbContext(options)) { //Given var userService = new UserService(context); var musicbrainzService = new MusicbrainzService(); var service = new MessageService(userService, musicbrainzService); var text = "add nofx"; var rawMessage = TestHelper.rawMessageFactory(text); var messageModel = messageModelFactory(text); //When var actualMessage = service.GetMessage(rawMessage); var expectedMessage = messageModel; //Then Assert.NotNull(actualMessage); Assert.Equal(expectedMessage.UtcDate, actualMessage.UtcDate); Assert.Equal(expectedMessage.ExternalUserId, actualMessage.ExternalUserId); Assert.Equal(expectedMessage.FirstName, actualMessage.FirstName); Assert.Equal(expectedMessage.LastName, actualMessage.LastName); Assert.Equal(expectedMessage.MessageId, actualMessage.MessageId); Assert.Equal(expectedMessage.Text, actualMessage.Text); Assert.Equal(expectedMessage.Username, actualMessage.Username); } }
public async Task PerformActionTest_ShouldSuspendUserActivity() { //Given var options = TestHelper.optionsFactory("suspend_user_db"); var expectedUser = new UserModel() { Id = new Guid(), ExternalId = 1, CreatedAtUtc = DateTime.UtcNow, IsActive = true }; using (var context = new MusichinoDbContext(options)) { var userService = new UserService(context); var musicbrainzService = new MusicbrainzService(); var service = new MessageService(userService, musicbrainzService); await context.Users.AddAsync(expectedUser); await context.SaveChangesAsync(); // When await service.PerformAction(Commands.Suspend, expectedUser.Id, null); var actualUser = await context.Users.FirstOrDefaultAsync(u => u.Id == expectedUser.Id); //Then Assert.NotNull(actualUser); Assert.Equal(actualUser.IsActive, false); } }
public void TestGetMessageCommand_ShouldThrowInvalidDataException() { var options = TestHelper.optionsFactory("add_artist_db"); using (var context = new MusichinoDbContext(options)) { //Given var userService = new UserService(context); var musicbrainzService = new MusicbrainzService(); var service = new MessageService(userService, musicbrainzService); //Then Assert.Throws <InvalidDataException>(() => service.GetMessageCommand(" ")); Assert.Throws <InvalidDataException>(() => service.GetMessageCommand("")); Assert.Throws <InvalidDataException>(() => service.GetMessageCommand(null)); Assert.Throws <InvalidDataException>(() => service.GetMessageCommand(" ")); } }
public async Task PerformActionTest_ShouldAddArtist() { // Given var options = TestHelper.optionsFactory("add_artist_db"); var expectedUser = new UserModel() { Id = new Guid(), ExternalId = 1, CreatedAtUtc = DateTime.UtcNow, IsActive = true }; var message = new MessageCommand() { Text = "search nofx" }; using (var context = new MusichinoDbContext(options)) { // When var userService = new UserService(context); var musicbrainzService = new MusicbrainzService(); var service = new MessageService(userService, musicbrainzService); await context.Users.AddAsync(expectedUser); await context.SaveChangesAsync(); await service.PerformAction(Commands.Search, expectedUser.Id, message); var actualUser = await context.Users.FirstOrDefaultAsync(u => u.Id == expectedUser.Id); var actualArtist = await context.Artists.FirstOrDefaultAsync(a => a.Name == "nofx"); var actualArtistUser = await context.ArtistUsers.FirstOrDefaultAsync(); //Then Assert.NotEmpty(context.Artists); Assert.NotNull(actualArtist); Assert.NotNull(actualArtistUser); Assert.Equal("nofx", actualArtist.Name.ToLower()); Assert.Equal(expectedUser.Id, actualArtistUser.UserId); } }
public void TestGetMessageCommand_ShouldReturnSuspend() { var options = TestHelper.optionsFactory("add_artist_db"); using (var context = new MusichinoDbContext(options)) { //Given var userService = new UserService(context); var musicbrainzService = new MusicbrainzService(); var service = new MessageService(userService, musicbrainzService); var text = "suspend"; var rawMessage = TestHelper.rawMessageFactory(text); var messageModel = messageModelFactory(text); //When var actualText = service.GetMessageCommand(messageModel.Text); var expectedText = MessageService.Commands.Suspend; //Then Assert.Equal(expectedText, actualText); } }
public async Task TestReadRequestBodyAsync_ShouldReturnString() { var options = TestHelper.optionsFactory("add_artist_db"); using (var context = new MusichinoDbContext(options)) { //Given var userService = new UserService(context); var musicbrainzService = new MusicbrainzService(); var service = new MessageService(userService, musicbrainzService); var rawMessage = TestHelper.rawMessageFactory("add nofx"); //When using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(rawMessage))) { var result = await service.ReadRequestBodyAsync(stream); //Then Assert.Equal(rawMessage, result); } } }
public WebHook(MusicbrainzService musicbrainz, MessageService message, UserService user) { _musicbrainz = musicbrainz; _message = message; _user = user; }