Exemple #1
0
        public async Task WriteToDbAsync(bool isShutdownRequested = false)
        {
            using (var repo = new CommentRepository())
            {
                var data = _commentCollection.GetItemsToInsert(isShutdownRequested);

                if (data.Any())
                {
                    await repo.AddRangeAsync(data);

                    await repo.SaveAsync();

                    _commentCollection.manualResetEvent.Set();
                    _commentCollection.manualResetEvent.Reset();
                }
            }
        }
Exemple #2
0
        public async Task ShouldReturnCommentsLazyLoadResult()
        {
            // Arrange
            Guid   deviceId             = _baseTest.Fixture.Create <Guid>();
            string comment              = _baseTest.Fixture.Create <string>();
            Guid   userId               = _baseTest.Fixture.Create <Guid>();
            string userName             = _baseTest.Fixture.Create <string>();
            string userNameNewForAssert = _baseTest.Fixture.Create <string>();

            LazyLoadParameters filter = new LazyLoadParameters()
            {
                Limit  = 1,
                Offset = 2
            };

            var commentList = _baseTest.Fixture.Build <Comment>()
                              .With(x => x.Message, comment)
                              .With(x => x.CreateOn, DateTime.UtcNow)
                              .With(x => x.DeviceId, deviceId)
                              .With(x => x.UserId, userId)
                              .With(x => x.UserName, userName)
                              .Without(x => x.Device)
                              .CreateMany(4);

            var userStubList = _baseTest.Fixture.Build <UserModel>()
                               .With(x => x.CompanyId, 2222)
                               .With(x => x.DisplayName, userNameNewForAssert)
                               .With(x => x.Id, userId)
                               .CreateMany(1).ToList();

            await _commrepository.AddRangeAsync(commentList);

            _httpServiceMock.Setup(x => x.GetUsersByIdTrustedAsync(It.IsAny <string>())).ReturnsAsync(userStubList);

            // Act
            var result = await _commentService.GetAllByDeviceIdAsync(It.IsAny <string>(), deviceId, filter);

            //Assert
            var commentsresult = result.Result.FirstOrDefault();

            commentsresult.UserName.Should().Be(userNameNewForAssert);

            result.Result.Count().Should().Be(1);
            result.Total.Should().Be(4);
        }