Пример #1
0
        public async Task UpsertReviewShouldUpdateReviewInFileIfExistsWithSameReview(string fileName, string guidStr, int itemCount)
        {
            // Arrange
            var    mockFileSystem = new MockFileSystem();
            string path           = $@"C:\tmp\{fileName}.json";
            var    mockInputFile  = new MockFileData(FileStrings.GetFile(fileName));

            mockFileSystem.AddFile(path, mockInputFile);
            IAsyncContentManager contentManager = new FileContentManager(path, mockFileSystem);
            Guid   guid         = new(guidStr);
            Review reviewToSave = new()
            {
                Guid      = guid,
                EndDate   = DateTime.MaxValue,
                StartDate = DateTime.Today,
                Status    = ReviewStatus.Archived,
                Records   = new List <Record>()
            };

            // Act
            await contentManager.UpsertReviewAsync(reviewToSave);

            List <Review> reviews = await contentManager.GetReviewsAsync();

            Review savedReview = reviews.FirstOrDefault(r => r.Guid == guid);

            // Assert
            Assert.IsNotNull(savedReview);
            Assert.IsTrue(mockFileSystem.File.Exists(path));
            Assert.AreEqual(itemCount, reviews.Count);
            Assert.AreEqual(reviewToSave, savedReview);
        }
    }
Пример #2
0
        public async Task UpsertReviewShouldAddReviewToFileIfExistsWithoutSameReview()
        {
            // Arrange
            string fileName       = "oneReview";
            var    mockFileSystem = new MockFileSystem();
            string path           = $@"C:\tmp\{fileName}.json";
            var    mockInputFile  = new MockFileData(FileStrings.GetFile(fileName));

            mockFileSystem.AddFile(path, mockInputFile);
            IAsyncContentManager contentManager = new FileContentManager(path, mockFileSystem);
            Guid   guid         = new("7176da9a-3670-4fe3-8d11-cb19d697620e");
            Review reviewToSave = new()
            {
                Guid      = guid,
                EndDate   = DateTime.MaxValue,
                StartDate = DateTime.Today,
                Status    = ReviewStatus.Active,
                Records   = new List <Record>()
            };

            // Act
            await contentManager.UpsertReviewAsync(reviewToSave);

            List <Review> reviews = await contentManager.GetReviewsAsync();

            Review savedReview = reviews.FirstOrDefault(r => r.Guid == guid);

            // Assert
            Assert.IsTrue(mockFileSystem.File.Exists(path));
            Assert.AreEqual(2, reviews.Count);
            Assert.AreEqual(reviewToSave, savedReview);
        }
Пример #3
0
        public async Task UpsertReviewShouldCreateJsonfileWithReviewIfNoneExist()
        {
            // Arrange
            string fileName       = "savedReview";
            var    mockFileSystem = new MockFileSystem();

            mockFileSystem.AddDirectory(@"C:\tmp\");
            string path = $@"C:\tmp\{fileName}.json";
            IAsyncContentManager contentManager = new FileContentManager(path, mockFileSystem);
            Guid   guid         = new Guid("7176da9a-3670-4fe3-8d11-cb19d697620e");
            Review reviewToSave = new()
            {
                Guid      = guid,
                EndDate   = DateTime.MaxValue,
                StartDate = DateTime.Today,
                Status    = ReviewStatus.Active,
                Records   = new List <Record>()
            };

            // Act
            await contentManager.UpsertReviewAsync(reviewToSave);

            Review savedReview = (await contentManager.GetReviewsAsync())[0];

            // Assert
            Assert.IsTrue(mockFileSystem.File.Exists(path));
            Assert.AreEqual(reviewToSave, savedReview);
        }
Пример #4
0
        public async Task GetReviewsShouldReturnEmptyListIfFileNotExists()
        {
            // Arrange
            var    mockFileSystem = new MockFileSystem();
            string path           = Path.Combine(Environment.CurrentDirectory, "data", "donotexist.json");
            IAsyncContentManager contentManager = new FileContentManager(path, mockFileSystem);

            // Act
            List <Review> reviews = await contentManager.GetReviewsAsync();

            // Assert
            Assert.IsFalse(reviews.Any());
        }
Пример #5
0
        public async Task GetReviewsShouldReturnStoredListIfFileIsCorrect(string fileName, int expectedCount)
        {
            // Arrange
            var    mockFileSystem = new MockFileSystem();
            var    mockInputFile  = new MockFileData(FileStrings.GetFile(fileName));
            string path           = $@"C:\tmp\{fileName}.json";

            mockFileSystem.AddFile(path, mockInputFile);
            IAsyncContentManager contentManager = new FileContentManager(path, mockFileSystem);

            // Act
            List <Review> reviews = await contentManager.GetReviewsAsync();

            // Assert
            Assert.AreEqual(expectedCount, reviews.Count());
        }
Пример #6
0
        public async Task GetReviewsShouldReturnEmptyListIfFileIsEmpty()
        {
            // Arrange
            var    mockFileSystem = new MockFileSystem();
            var    mockInputFile  = new MockFileData(FileStrings.GetFile("empty"));
            string path           = @"C:\tmp\empty.json";

            mockFileSystem.AddFile(path, mockInputFile);
            IAsyncContentManager contentManager = new FileContentManager(path, mockFileSystem);

            // Act
            List <Review> reviews = await contentManager.GetReviewsAsync();

            // Assert
            Assert.IsFalse(reviews.Any());
        }