public void RepositoryReturnsChannelItemsFromDatabase() { var informationCollection = new MongoCollectionReturnsSpecificDocumentsStub(new List <InformationEntry> { new InformationEntry { InformationId = "Steam.de.Sims4" }, new InformationEntry { InformationId = "Nintendo.de.Zelda-Twilight-Princess" } }); var database = new MongoDatabaseSpy(new Dictionary <string, IMongoCollection <InformationEntry> > { { "information", informationCollection } }); var repository = new GetChannelMongoDatabaseRepository(database); var channel = repository.GetChannel(); var expectedInformationIds = new[] { "Steam.de.Sims4", "Nintendo.de.Zelda-Twilight-Princess" }; Assert.Equal( JsonConvert.SerializeObject(new Channel { InformationItemIds = expectedInformationIds }), JsonConvert.SerializeObject(channel) ); }
public void RepositorySelectsCollectionInformationFromDatabase() { var database = new MongoDatabaseSpy(); var repository = new StoreInformationMongoDatabaseRepository(database); repository.StoreInformation(null); Assert.Equal("information", database.LastSelectedCollectionName); }
public void RepositorySelectsCollectionInformationFromDatabase() { var database = new MongoDatabaseSpy(); var repository = new GetChannelItemMongoDatabaseRepository(database); repository.GetChannelItem(string.Empty); Assert.Equal("information", database.LastSelectedCollectionName); }
public void RepositoryReturnsChannelItemFromDatabase() { var informationCollection = new MongoCollectionReturnsSpecificDocumentsStub(new List <InformationEntry> { new InformationEntry { InformationId = "Nintendo.de.Zelda-Twilight-Princess", Properties = new[] { new InformationPropertyEntry { Name = "titles", Values = new BsonValue[] { "The Legend of Zelda: Twilight Princess" } }, new InformationPropertyEntry { Name = "release-dates", Values = new BsonValue[] { DateTime.SpecifyKind(new DateTime(2016, 3, 4), DateTimeKind.Utc) } } } }, new InformationEntry { InformationId = "Steam.de.Sims4", Properties = new[] { new InformationPropertyEntry { Name = "titles", Values = new BsonValue[] { "Die Sims 4" } }, new InformationPropertyEntry { Name = "release-dates", Values = new BsonValue[] { DateTime.SpecifyKind(new DateTime(2014, 9, 2), DateTimeKind.Utc) } } } } }); var database = new MongoDatabaseSpy(new Dictionary <string, IMongoCollection <InformationEntry> > { { "information", informationCollection } }); var repository = new GetChannelItemMongoDatabaseRepository(database); var channelItem = repository.GetChannelItem("Nintendo.de.Zelda-Twilight-Princess"); var expectedJson = JsonConvert.SerializeObject(new ChannelItem { Id = "Nintendo.de.Zelda-Twilight-Princess", Properties = new Dictionary <string, IEnumerable <object> > { { "titles", new object[] { "The Legend of Zelda: Twilight Princess" } }, { "release-dates", new object[] { DateTime.SpecifyKind(new DateTime(2016, 3, 4), DateTimeKind.Utc) } } } }); var actualJson = JsonConvert.SerializeObject(channelItem); Assert.Equal(expectedJson, actualJson); }
public void RepositoryInsertNoInformationWhenIdenticalActiveInformationWithBamboozledPropertiesExists() { var existingEntries = new[] { new InformationEntry { InformationId = "234-BCD", IsActive = false, DiscoveryTimestamp = new DateTime(2017, 2, 3) }, new InformationEntry { InformationId = "234-BCD", IsActive = true, DiscoveryTimestamp = new DateTime(2017, 10, 4), Properties = new[] { new InformationPropertyEntry { Name = "titles", Values = new BsonValue[] { "information A", "information B", "information C" } }, new InformationPropertyEntry { Name = "prices", Values = new BsonValue[] { 12.50, 22.60 } }, } } }; var informationCollection = new MongoCollectionReturnsSpecificDocumentsStub(existingEntries); var database = new MongoDatabaseSpy(new Dictionary <string, IMongoCollection <InformationEntry> > { { "information", informationCollection } }); var id = "234-BCD"; var repository = new StoreInformationMongoDatabaseRepository(database); repository.StoreInformation(new InformationEntity { Id = id, Properties = new[] { new InformationPropertyEntity { Name = "prices", Values = new BsonValue[] { 22.60, 12.50 } }, new InformationPropertyEntity { Name = "titles", Values = new[] { "information B", "information C", "information A" } } } }); Assert.Null(informationCollection.ReplacedEntries); }
public void RepositoryInsertsInformationWithActiveFlagAndResetsActiveFlagsOfOlderVersionsWhenInformationDoesAlreadyExist() { var existingEntries = new[] { new InformationEntry { InformationId = "234-BCD", IsActive = false, DiscoveryTimestamp = new DateTime(2017, 2, 3) }, new InformationEntry { InformationId = "234-BCD", IsActive = true, DiscoveryTimestamp = new DateTime(2017, 10, 4) } }; var informationCollection = new MongoCollectionReturnsSpecificDocumentsStub(existingEntries); var database = new MongoDatabaseSpy(new Dictionary <string, IMongoCollection <InformationEntry> > { { "information", informationCollection } }); var id = "234-BCD"; var repository = new StoreInformationMongoDatabaseRepository(database); repository.StoreInformation(new InformationEntity { Id = id, Properties = new[] { new InformationPropertyEntity { Name = "titles", Values = new[] { "title A" } } } }); var expectedEntry = new InformationEntry { InformationId = id, IsActive = true, DiscoveryTimestamp = MongoCollectionReturnsSpecificDocumentsStub.DiscoveryTimestamp, Properties = new[] { new InformationPropertyEntry { Name = "titles", Values = new BsonValue[] { "title A" } } } }; Assert.Equal( JsonConvert.SerializeObject(expectedEntry), JsonConvert.SerializeObject(informationCollection.LastInsertedEntry) ); existingEntries[1].IsActive = false; Assert.Equal( JsonConvert.SerializeObject(existingEntries), JsonConvert.SerializeObject(informationCollection.ReplacedEntries) ); }
public void RepositoryInsertsInformationWithActiveFlagAndDiscoveryTimestampWhenInformationDoesNotAlreadyExist() { var informationCollection = new MongoCollectionReturnsSpecificDocumentsStub(new List <InformationEntry>()); var database = new MongoDatabaseSpy(new Dictionary <string, IMongoCollection <InformationEntry> > { { "information", informationCollection } }); var id = "123-ABC"; var repository = new StoreInformationMongoDatabaseRepository(database); repository.StoreInformation(new InformationEntity { Id = id }); var expectedEntry = new InformationEntry { InformationId = id, IsActive = true, DiscoveryTimestamp = MongoCollectionReturnsSpecificDocumentsStub.DiscoveryTimestamp }; Assert.Equal( JsonConvert.SerializeObject(expectedEntry), JsonConvert.SerializeObject(informationCollection.LastInsertedEntry) ); }
public void RepositoryInsertsInformationAsNewRecord() { var informationCollection = new MongoCollectionSpy(); var database = new MongoDatabaseSpy(new Dictionary <string, IMongoCollection <InformationEntry> > { { "information", informationCollection } }); var repository = new StoreInformationMongoDatabaseRepository(database); repository.StoreInformation(new InformationEntity { Properties = new[] { new InformationPropertyEntity { Name = "title", Values = new object[] { "sweet shoes" } }, new InformationPropertyEntity { Name = "color", Values = new object[] { "red" } }, new InformationPropertyEntity { Name = "price", Values = new object[] { (decimal)12.45 } }, new InformationPropertyEntity { Name = "currency", Values = new object[] { "€" } }, new InformationPropertyEntity { Name = "size", Values = new object[] { 43 } } } }); var insertedEntry = informationCollection.LastInsertedEntry; var expectedEntry = new InformationEntry { IsActive = true, Properties = new[] { new InformationPropertyEntry { Name = "color", Values = new BsonString[] { "red" } }, new InformationPropertyEntry { Name = "currency", Values = new BsonString[] { "€" } }, new InformationPropertyEntry { Name = "price", Values = new BsonDecimal128[] { new BsonDecimal128((decimal)12.45) } }, new InformationPropertyEntry { Name = "size", Values = new BsonValue[] { new BsonInt32(43) } }, new InformationPropertyEntry { Name = "title", Values = new BsonString[] { "sweet shoes" } } }, DiscoveryTimestamp = MongoCollectionSpy.DiscoveryTimestamp }; Assert.Equal( JsonConvert.SerializeObject(expectedEntry), JsonConvert.SerializeObject(insertedEntry) ); }