public async Task ComparisonRecordExistsWithFiles_Retrieve_FilesAreRetrieved()
        {
            // Arrange
            const int id        = 1;
            var       rightFile = Convert.FromBase64String(TestConstants.File1Base64Content);
            var       leftFile  = Convert.FromBase64String(TestConstants.File1Base64Content);
            var       data      = new List <FileComparison>()
            {
                new FileComparison()
                {
                    Id = id, Right = rightFile, Left = leftFile
                }
            }.AsQueryable();
            var mockSet = await Task.Run(() => MockContextHelper.SetupMockSet(data));

            var mockContext = await Task.Run(() => MockContextHelper.SetupMockContext(mockSet));

            var retrieveService = new RetrieveService(mockContext.Object);

            // Act
            var files = await retrieveService.GetFilesAsync(id);

            // Assert
            Assert.IsNotNull(files, "Retrieved record should not be null!");
            Assert.IsNotNull(files.Left, "Left file should not be null!");
            Assert.IsNotNull(files.Right, "Right file should not be null!");
        }
        public async Task ComparisonRecordExistsLeftNotNull_LeftExists_True()
        {
            // Arrange
            const int id        = 1;
            var       leftFile  = Convert.FromBase64String(TestConstants.File1Base64Content);
            var       rightFile = Convert.FromBase64String(TestConstants.File1Base64Content);
            var       data      = new List <FileComparison>()
            {
                new FileComparison()
                {
                    Id = id, Right = rightFile, Left = leftFile
                }
            }.AsQueryable();
            var mockSet = await Task.Run(() => MockContextHelper.SetupMockSet(data));

            var mockContext = await Task.Run(() => MockContextHelper.SetupMockContext(mockSet));

            var retrieveService = new RetrieveService(mockContext.Object);

            // Act
            var result = await retrieveService.LeftFileExistsAsync(id);

            // Assert
            Assert.IsTrue(result, "Retrieved result should be true!");
        }
Beispiel #3
0
        public async Task RightFileNull_Upload_ThrowException()
        {
            // Arrange
            const int id      = 1;
            var       data    = new List <FileComparison>().AsQueryable();
            var       mockSet = await Task.Run(() => MockContextHelper.SetupMockSet(data));

            var mockContext = await Task.Run(() => MockContextHelper.SetupMockContext(mockSet));

            var uploadService = new UploadService(mockContext.Object);

            // Act
            var exceptionThrown = false;

            try
            {
                await uploadService.UploadRightAsync(id, null);
            }
            catch (ArgumentNullException)
            {
                exceptionThrown = true;
            }

            // Assert
            Assert.IsTrue(exceptionThrown, "ArgumentNullException was not thrown!");
        }
Beispiel #4
0
        /// <summary>
        /// Sets up and returns the mock context.
        /// </summary>
        /// <param name="id">The comparison ID.</param>
        /// <param name="leftFile">The left file.</param>
        /// <param name="rightFile">The right file.</param>
        /// <returns>Mock <see cref="FileDiffContext"/> object.</returns>
        private static Mock <FileDiffContext> GetMockContext(int id, byte[] leftFile, byte[] rightFile)
        {
            var data = new List <FileComparison>
            {
                new FileComparison()
                {
                    Id = id, Left = leftFile, Right = rightFile
                }
            }.AsQueryable();

            var mockSet = MockContextHelper.SetupMockSet(data);

            return(MockContextHelper.SetupMockContext(mockSet));
        }
Beispiel #5
0
        public async Task RecordExists_UploadRight_Success()
        {
            // Arrange
            const int id        = 1;
            var       rightFile = Convert.FromBase64String(TestConstants.File1Base64Content);
            var       leftFile  = Convert.FromBase64String(TestConstants.File1Base64Content);
            var       data      = new List <FileComparison>()
            {
                new FileComparison()
                {
                    Id = id, Right = rightFile, Left = leftFile
                }
            }.AsQueryable();
            var mockSet = await Task.Run(() => MockContextHelper.SetupMockSet(data));

            var mockContext = await Task.Run(() => MockContextHelper.SetupMockContext(mockSet));

            var uploadService = new UploadService(mockContext.Object);

            // Act
            await uploadService.UploadRightAsync(id, rightFile);

            // Assert
            var recordAddedToDbSet = true;
            var changesSaved       = true;

            try
            {
                mockSet.Verify(m => m.Add(It.IsAny <FileComparison>()), Times.Once());
            }
            catch (MockException)
            {
                recordAddedToDbSet = false;
            }

            try
            {
                mockContext.Verify(m => m.SaveChangesAsync(), Times.Once());
            }
            catch (MockException)
            {
                changesSaved = false;
            }

            Assert.IsFalse(recordAddedToDbSet, "Existing record should be updated instead of adding a new one!");
            Assert.IsTrue(changesSaved, "Changes were not saved to context!");
        }
        public async Task ComparisonRecordNotExistsWithFiles_Retrieve_NullRetrieved()
        {
            // Arrange
            const int id      = 1;
            var       data    = new List <FileComparison>().AsQueryable();
            var       mockSet = await Task.Run(() => MockContextHelper.SetupMockSet(data));

            var mockContext = await Task.Run(() => MockContextHelper.SetupMockContext(mockSet));

            var retrieveService = new RetrieveService(mockContext.Object);

            // Act
            var files = await retrieveService.GetFilesAsync(id);

            // Assert
            Assert.IsNull(files, "Retrieved record should be null!");
        }