Esempio n. 1
0
        public async Task PostDiffDataShouldInsertOnlyLeftDataWhenCallToLeftDataIsValid()
        {
            // Arrange
            var someValidId  = int.MaxValue;
            var validData    = new byte[] { 1, 2, 3, 4, 5 };
            var diffAnaliser = new DiffAnalyser();

            // Act
            IHttpActionResult response = await _diffController.PostLeftDiffData(someValidId, _leftBase64StringValidData);

            // Assert
            Assert.IsInstanceOfType(response, typeof(OkResult));
            // Only the newly created record should be present.
            Assert.AreEqual(1, _repository.DiffDataCount());

            InMemoryDiffData savedData = _repository.GetById(someValidId);

            // The record in db should be retrieved with the provided id via API call.
            Assert.IsNotNull(savedData);

            // The left data stored should be the same as provided via API call.
            Assert.IsTrue(validData.SequenceEqual(savedData.Left));

            // Right should not contains any data, since the record was created
            // and only left data was provided.
            Assert.AreEqual(null, savedData.Right);
        }
Esempio n. 2
0
        public async Task PostLeftDiffDataShouldReturnStatusCodeOkWhenNoErrorsOccurs()
        {
            // Arrange
            var someValidId    = int.MaxValue;
            var diffController = new DiffController(_defaultRepositoryMock.Object, _defaultDiffAnalyserMock.Object, _defaultMapperMock.Object);

            // Act
            IHttpActionResult result = await diffController.PostLeftDiffData(someValidId, _validBase64string);

            // Assert
            Assert.IsInstanceOfType(result, typeof(OkResult));
        }
Esempio n. 3
0
        public async Task PostLeftDiffDataShouldReturnInternalServerErrorWhenSomeUnexpectedErrorsOccurs()
        {
            // Arrange
            var someValidId    = int.MaxValue;
            var repositoryMock = new Mock <IDiffRepositoryManager>();

            repositoryMock
            .Setup(r => r.Save(It.IsAny <int>(), It.IsAny <string>(), It.IsAny <DiffItemType>()))
            .ThrowsAsync(new Exception());

            var diffController = new DiffController(repositoryMock.Object, _defaultDiffAnalyserMock.Object, _defaultMapperMock.Object);

            // Act
            IHttpActionResult result = await diffController.PostLeftDiffData(someValidId, _validBase64string);

            // Assert
            Assert.IsInstanceOfType(result, typeof(InternalServerErrorResult));
        }