Exemple #1
0
        public void Parse_songs_from_database_response__one_song()
        {
            // Arrange
            var dynamodbClient  = new Mock <IAmazonDynamoDB>(MockBehavior.Strict);
            var jukeboxDynamoDb = new JukeboxDynamoDb(dynamodbClient.Object, SongFixtures.TableName, SongFixtures.IndexNameSearchTitle, SongFixtures.IndexNameSearchTitleArtist, SongFixtures.TableName);
            var items           = new List <Dictionary <string, AttributeValue> > {
                {
                    new Dictionary <string, AttributeValue> {
                        { "song_number", new AttributeValue {
                              S = "123"
                          } },
                        { "artist", new AttributeValue {
                              S = "Lionel Ritche"
                          } },
                        { "title", new AttributeValue {
                              S = "Hello"
                          } }
                    }
                }
            };
            var quesryResponse = new QueryResponse {
                Items = items
            };

            // Act
            var parsedSongsList = jukeboxDynamoDb.ParseSongsFromDatabaseResponse(quesryResponse).ToList();

            // Assert
            Assert.Equal("Lionel Ritche", parsedSongsList.FirstOrDefault().Artist);
            Assert.Equal("123", parsedSongsList.FirstOrDefault().SongNumber);
            Assert.Equal("Hello", parsedSongsList.FirstOrDefault().Title);
        }
Exemple #2
0
        public async Task Find_songs_by_title_artist__found_song()
        {
            // Arrange
            var queryResponse = new QueryResponse {
                Items = new List <Dictionary <string, AttributeValue> > {
                    new Dictionary <string, AttributeValue> {
                        { "song_number", new AttributeValue {
                              S = "123"
                          } },
                        { "artist", new AttributeValue {
                              S = "Lionel Ritche"
                          } },
                        { "title", new AttributeValue {
                              S = "Hello"
                          } }
                    }
                }
            };
            var dynamodbClient = new Mock <IAmazonDynamoDB>(MockBehavior.Strict);

            dynamodbClient.Setup(x => x.QueryAsync(It.Is <QueryRequest>(y => y.TableName == SongFixtures.TableName), new CancellationToken())).Returns(Task.FromResult(queryResponse));
            var jukeboxDynamoDb = new JukeboxDynamoDb(dynamodbClient.Object, SongFixtures.TableName, SongFixtures.IndexNameSearchTitle, SongFixtures.IndexNameSearchTitleArtist, SongFixtures.TableName);

            // Act
            var parsedSongsList = (await jukeboxDynamoDb.FindSongsByTitleArtistAsync("i will wait", "mumford & sons")).ToList();

            // Assert
            Assert.Equal("Lionel Ritche", parsedSongsList.FirstOrDefault().Artist);
            Assert.Equal("123", parsedSongsList.FirstOrDefault().SongNumber);
            Assert.Equal("Hello", parsedSongsList.FirstOrDefault().Title);
        }
Exemple #3
0
        //--- Constructors ---
        public override Task InitializeAsync(LambdaConfig config)
        {
            var tableName                  = AwsConverters.ConvertDynamoDBArnToName(config.ReadText(("DynamoDbSongs")));
            var indexNameSearchTitle       = config.ReadText("DynamoDbIndexNameSearchTitleName");
            var indexNameSearchTitleArtist = config.ReadText("DynamoDbIndexNameSearchTitleArtistName");
            var indexTableName             = AwsConverters.ConvertDynamoDBArnToName(config.ReadText("DynamoDbTitleWordCache"));

            _jukeboxDynamoDb = new JukeboxDynamoDb(new AmazonDynamoDBClient(), tableName, indexNameSearchTitle, indexNameSearchTitleArtist, indexTableName);
            _songlistUpload  = new Logic(this);
            return(Task.CompletedTask);
        }
Exemple #4
0
        //--- Constructors ---
        public override Task InitializeAsync(LambdaConfig config)
        {
            var queueName                  = config.ReadText("SqsSongQueue");
            var tableName                  = AwsConverters.ConvertDynamoDBArnToName(config.ReadText("DynamoDbSongs"));
            var indexNameSearchTitle       = config.ReadText("DynamoDbIndexNameSearchTitleName");
            var indexNameSearchTitleArtist = config.ReadText("DynamoDbIndexNameSearchTitleArtistName");
            var indexTableName             = AwsConverters.ConvertDynamoDBArnToName(config.ReadText("DynamoDbTitleWordCache"));

            _jukeboxDynamoDb = new JukeboxDynamoDb(new AmazonDynamoDBClient(), tableName, indexNameSearchTitle, indexNameSearchTitleArtist, indexTableName);
            _playSongRequest = new PlaySongNumberRequest(this, new AmazonSQSClient(), queueName, this);
            return(Task.CompletedTask);
        }
        public async Task Find_songs_by_title__found_multiple_songs()
        {
            // Arrange
            var queryResponse = new QueryResponse {
                Items = new List <Dictionary <string, AttributeValue> > {
                    new Dictionary <string, AttributeValue> {
                        { "song_number", new AttributeValue {
                              S = "123"
                          } },
                        { "artist", new AttributeValue {
                              S = "Lionel Ritche"
                          } },
                        { "title", new AttributeValue {
                              S = "Hello"
                          } }
                    },
                    new Dictionary <string, AttributeValue> {
                        { "song_number", new AttributeValue {
                              S = "789"
                          } },
                        { "artist", new AttributeValue {
                              S = "Adele"
                          } },
                        { "title", new AttributeValue {
                              S = "Hello"
                          } }
                    }
                }
            };
            var dynamodbClient = new Mock <IAmazonDynamoDB>(MockBehavior.Strict);

            dynamodbClient.Setup(x => x.QueryAsync(It.Is <QueryRequest>(y => y.TableName == SongFixtures.TableName), new CancellationToken())).Returns(Task.FromResult(queryResponse));
            var jukeboxDynamoDb = new JukeboxDynamoDb(dynamodbClient.Object, SongFixtures.TableName, SongFixtures.IndexNameSearchTitle, SongFixtures.IndexNameSearchTitleArtist, SongFixtures.TableName);

            // Act
            var parsedSongsList = (await jukeboxDynamoDb.FindSongsByTitleAsync("hello")).ToList();

            // Assert
            foreach (var song in parsedSongsList)
            {
                if (song.Artist == "Lionel Ritche")
                {
                    Assert.True(true);
                }
            }

            var foundArtist1 = parsedSongsList.Find(x => x.Artist == "Lionel Ritche").Artist;
            var foundArtist2 = parsedSongsList.Find(x => x.Artist == "Adele").Artist;

            Assert.Equal("Lionel Ritche", foundArtist1);
            Assert.Equal("Adele", foundArtist2);
        }
        public void Query_request__title()
        {
            // Arrange
            var dynamodbClient  = new Mock <IAmazonDynamoDB>(MockBehavior.Strict);
            var jukeboxDynamoDb = new JukeboxDynamoDb(dynamodbClient.Object, SongFixtures.TableName, SongFixtures.IndexNameSearchTitle, SongFixtures.IndexNameSearchTitleArtist, SongFixtures.TableName);

            // Act
            var query = jukeboxDynamoDb.QueryRequestTitle("foo-bar");

            // Assert
            Assert.Contains("search_title = :v_song", query.KeyConditionExpression);
            query.ExpressionAttributeValues.TryGetValue(":v_song", out AttributeValue vSong);
            Assert.Contains("foo-bar", vSong.S);
        }
Exemple #7
0
        public void Query_request__number()
        {
            // Setup
            var dynamodbClient  = new Mock <IAmazonDynamoDB>(MockBehavior.Strict);
            var jukeboxDynamoDb = new JukeboxDynamoDb(dynamodbClient.Object, SongFixtures.TableName, SongFixtures.IndexNameSearchTitle, SongFixtures.IndexNameSearchTitleArtist, SongFixtures.TableName);

            // Act
            var query = jukeboxDynamoDb.QueryRequestNumber("123");

            // Assert
            Assert.Contains("song_number = :v_number", query.KeyConditionExpression);
            query.ExpressionAttributeValues.TryGetValue(":v_number", out AttributeValue vNumber);
            Assert.Contains("123", vNumber.S);
        }
Exemple #8
0
        public void Parse_songs_from_database_response__no_songs()
        {
            // Arrange
            var dynamodbClient  = new Mock <IAmazonDynamoDB>(MockBehavior.Strict);
            var jukeboxDynamoDb = new JukeboxDynamoDb(dynamodbClient.Object, SongFixtures.TableName, SongFixtures.IndexNameSearchTitle, SongFixtures.IndexNameSearchTitleArtist, SongFixtures.TableName);
            var items           = new List <Dictionary <string, AttributeValue> >();
            var quesryResponse  = new QueryResponse {
                Items = items
            };

            // Act
            var parsedSongsList = jukeboxDynamoDb.ParseSongsFromDatabaseResponse(quesryResponse).ToList();

            // Assert
            Assert.Empty(parsedSongsList);
        }
Exemple #9
0
        public async Task Find_songs_by_title_artist__found_no_songs()
        {
            // Arrange
            var queryResponse = new QueryResponse {
                Items = new List <Dictionary <string, AttributeValue> >()
            };
            var dynamodbClient = new Mock <IAmazonDynamoDB>(MockBehavior.Strict);

            dynamodbClient.Setup(x => x.QueryAsync(It.Is <QueryRequest>(y => y.TableName == SongFixtures.TableName), new CancellationToken())).Returns(Task.FromResult(queryResponse));
            var jukeboxDynamoDb = new JukeboxDynamoDb(dynamodbClient.Object, SongFixtures.TableName, SongFixtures.IndexNameSearchTitle, SongFixtures.IndexNameSearchTitleArtist, SongFixtures.TableName);

            // Act
            var parsedSongsList = await jukeboxDynamoDb.FindSongsByTitleArtistAsync("foo-bar", "foo-bar");

            // Assert
            Assert.Empty(parsedSongsList);
        }