public async Task GetStatisticsCollectionWithNonEmptyStatsList_ReturnsSerializedList() { // arrange var collectionRepositoryMock = new Mock<IRepository<DbCollection>>(); var statisticsRepositoryMock = new Mock<IRepository<StatisticsEntity>>(); var testDbCollection = new DbCollection { Id = "1", Description = "descr1", MembersCount = 1, Name = "name1", PrivacySettings = 0, ScreenName = "sname1", StatisticsList = new List<string> { "aaa", "bbb", "ccc" } }; collectionRepositoryMock.Setup(m => m.GetByIdAsync(It.IsAny<long>())).ReturnsAsync(testDbCollection); var controller = new HomeController(collectionRepositoryMock.Object, statisticsRepositoryMock.Object); // act var result = (await controller.GetStatisticCollections(1)).Data as List<string>; // assert Assert.That(result.Count, Is.EqualTo(testDbCollection.StatisticsList.Count)); Assert.That(result[0], Is.EqualTo(testDbCollection.StatisticsList[0])); }
public async Task GetStatisticsCollectionForEmptyStatisticsList_ReturnsNull() { // arrange var collectionRepositoryMock = new Mock<IRepository<DbCollection>>(); var statisticsRepositoryMock = new Mock<IRepository<StatisticsEntity>>(); collectionRepositoryMock.Setup(m => m.GetByIdAsync(It.IsAny<long>())).ReturnsAsync(new DbCollection() { Id = "1", Description = "descr1", MembersCount = 1, Name = "name1", PrivacySettings = 0, ScreenName = "sname1", StatisticsList = new List<string>() }); var controller = new HomeController(collectionRepositoryMock.Object, statisticsRepositoryMock.Object); // act var result = await controller.GetStatisticCollections(1); // assert Assert.That(result, Is.Null); }
public async Task GetListCollections_ReturnsAllCollectionsFromRepository() { // arrange var collectionRepositoryMock = new Mock<IRepository<DbCollection>>(); var statisticsRepositoryMock = new Mock<IRepository<StatisticsEntity>>(); var testDbCollections = new List<DbCollection> { new DbCollection { Id = "1", Description = "descr1", MembersCount = 1, Name = "name1", PrivacySettings = 0, ScreenName = "sname1", StatisticsList = new List<string> { "aaa", "bbb", "ccc" } }, new DbCollection { Id = "2", Description = "descr2", MembersCount = 1, Name = "name2", PrivacySettings = 2, ScreenName = "sname2", StatisticsList = new List<string> { "ddd", "eee", "ccc" } } }; collectionRepositoryMock.Setup(m => m.GetAllAsync()).ReturnsAsync(testDbCollections); var controller = new HomeController(collectionRepositoryMock.Object, statisticsRepositoryMock.Object); // act var result = (await controller.GetListCollections()).Data as List<MongoCollection>; // assert Assert.That(result.Count, Is.EqualTo(testDbCollections.Count)); Assert.That(result[0].Name, Is.EqualTo(testDbCollections[0].ScreenName)); Assert.That(result[0].Index.ToString(), Is.EqualTo(testDbCollections[0].Id)); Assert.That(result[0].NameForTable, Is.EqualTo(testDbCollections[0].Name)); }
public async Task GetStatisticsForStatsType_ReturnsStatisticsModel() { // arrange var collectionRepositoryMock = new Mock<IRepository<DbCollection>>(); var statisticsRepositoryMock = new Mock<IRepository<StatisticsEntity>>(); var statistics = new List<StatisticsEntity> { new StatisticsEntity { Id = "groupName1", LastUpdateTime = new DateTime(1970,1,3), Statistics = new Dictionary<string, long> { {"key1", 1}, {"key2", 2} } }, new StatisticsEntity { Id = "groupName2", LastUpdateTime = new DateTime(1970,1,10), Statistics = new Dictionary<string, long> { {"key3", 3}, {"key4", 4} } } }; statisticsRepositoryMock.Setup(m => m.GetAllAsync()).ReturnsAsync(statistics); var controller = new HomeController(collectionRepositoryMock.Object, statisticsRepositoryMock.Object); // act var result = (await controller.GetStatistics("groupName2", "123")).Data as List<StatisticModel>; // assert Assert.That(result.Count, Is.EqualTo(statistics[1].Statistics.Count)); Assert.That(result[0].Field, Is.EqualTo("key3")); Assert.That(result[0].Count, Is.EqualTo(statistics[1].Statistics["key3"])); Assert.That(result[1].Field, Is.EqualTo("key4")); Assert.That(result[1].Count, Is.EqualTo(statistics[1].Statistics["key4"])); }