public void VerifyMocks()
 {
     ImageDataAccessMock.VerifyAll();
     ImageDataAccessMock.VerifyNoOtherCalls();
     LearningDataAccessMock.VerifyAll();
     LearningDataAccessMock.VerifyNoOtherCalls();
 }
        public void Update_ShouldCallUpdateOnDataLayer_WhenProvidingValidUpdateRequest()
        {
            // Arrange
            var updatedDataDto = new LearningDataDto()
            {
                Id          = 0,
                Name        = "New Name",
                Description = "New description",
                Number      = 911,
                ImageData   = "QUJD",
                ImageTitle  = "New Title",
                CategoryId  = 42
            };
            var expectedLearningData = new LearningData()
            {
                LearningDataId = updatedDataDto.Id,
                Name           = updatedDataDto.Name,
                Description    = updatedDataDto.Description,
                Number         = updatedDataDto.Number,
                CategoryId     = updatedDataDto.CategoryId
            };
            var expectedImageData = new ImageData()
            {
                LearningDataId = updatedDataDto.Id,
                Title          = updatedDataDto.ImageTitle,
                Data           = Convert.FromBase64String(updatedDataDto.ImageData)
            };

            ImageDataAccessMock.Setup(x => x.UpdateImageData(It.IsAny <ImageData>())).Returns(true);
            LearningDataAccessMock.Setup(x => x.UpdateLearningData(It.IsAny <LearningData>())).Returns(true);

            // Act
            Sut.Update(updatedDataDto);

            // Assert
            // We need to verify mocks manually since object arguments are being provided
            LearningDataAccessMock.Verify(mock => mock.UpdateLearningData(
                                              It.Is <LearningData>(data => CompareLearningData(data, expectedLearningData))
                                              ));
            LearningDataAccessMock.VerifyNoOtherCalls();

            ImageDataAccessMock.Verify(mock => mock.UpdateImageData(
                                           It.Is <ImageData>(data => CompareImageData(data, expectedImageData))
                                           ));
            ImageDataAccessMock.VerifyNoOtherCalls();
        }
        public void Add_ShouldStoreLearningDataInDataLayer_WhenValidObjectIsProvided()
        {
            // Arrange
            var expectedPrimaryKey = 5;
            var expectedImageData  = new ImageData()
            {
                LearningDataId = expectedPrimaryKey,
                Data           = LearningDataRepoTestData.DummyImageData1.Data,
                Title          = LearningDataRepoTestData.DummyImageData1.Title
            };
            var expectedLearningData = new LearningData()
            {
                LearningDataId = expectedPrimaryKey,
                Name           = LearningDataRepoTestData.DummyLearningData1.Name,
                Description    = LearningDataRepoTestData.DummyLearningData1.Description,
                Number         = LearningDataRepoTestData.DummyLearningData1.Number,
                CategoryId     = LearningDataRepoTestData.DummyLearningData1.CategoryId
            };

            ImageDataAccessMock.Setup(x => x.AddImageData(It.IsAny <ImageData>())).Returns(true);
            LearningDataAccessMock.Setup(x => x.AddLearningData(It.IsAny <LearningData>())).Returns(expectedPrimaryKey);

            // Act
            var actualPrimaryKey = Sut.Add(LearningDataRepoTestData.DummyLearningDto1);

            // Assert
            Assert.Equal(expectedPrimaryKey, actualPrimaryKey);

            // We need to verify mocks manually since object arguments are being provided
            LearningDataAccessMock.Verify(mock => mock.AddLearningData(
                                              It.Is <LearningData>(data => CompareLearningData(data, expectedLearningData))
                                              ));
            LearningDataAccessMock.VerifyNoOtherCalls();

            ImageDataAccessMock.Verify(mock => mock.AddImageData(
                                           It.Is <ImageData>(data => CompareImageData(data, expectedImageData))
                                           ));
            ImageDataAccessMock.VerifyNoOtherCalls();
        }