Esempio n. 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);
        }
    }
Esempio n. 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);
        }
Esempio n. 3
0
        public async Task GetReviewShouldReturnNullIfFileIsEmpty()
        {
            // 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
            Review review = await contentManager.GetReviewAsync(It.IsAny <Guid>());

            // Assert
            Assert.IsNull(review);
        }
Esempio n. 4
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());
        }
Esempio n. 5
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());
        }
Esempio n. 6
0
        public void GetReviewShouldThrowExceptionWhenNoMatch()
        {
            // Arrange
            string fileName       = "oneReview";
            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);
            Guid guid = new Guid("7176da9a-3670-4fe3-8d11-cb19d697620e");

            // Act
            // Assert
            Assert.ThrowsAsync <InvalidOperationException>(async() => await contentManager.GetReviewAsync(guid));
        }
Esempio n. 7
0
        public async Task GetReviewShouldReturnReviewIfOnlyMatch(string fileName, string guidStr, ReviewStatus expectedStatus)
        {
            // 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);
            Guid guid = new Guid(guidStr);

            // Act
            Review review = await contentManager.GetReviewAsync(guid);

            // Assert
            Assert.AreEqual(guid, review.Guid);
            Assert.AreEqual(expectedStatus, review.Status);
            Assert.AreEqual(new DateTime(2009, 02, 15), review.StartDate);
            Assert.AreEqual(new DateTime(2009, 02, 15), review.EndDate);
            Assert.IsNotNull(review.Records);
            Assert.IsFalse(review.Records.Any());
        }