Пример #1
0
        public void CreateShouldReturnNotOkWhenInsertOperationFailed()
        {
            var validationMock = new Mock <IValidator <SampleEntity> >();
            var loggerMock     = new Mock <ILogger>();
            var repositoryMock = new Mock <IRepository <SampleEntity> >();
            var requestObject  = new SampleEntity();

            loggerMock.Setup(v => v.Error(It.IsAny <string>()));
            repositoryMock.Setup(v => v.Create(requestObject)).Returns(0);
            var service = new SampleService(loggerMock.Object, repositoryMock.Object);

            // When
            var result = service.Create(requestObject);

            // Then
            Assert.False(result.IsSuccessed);
        }
Пример #2
0
        public void CreateShouldReturnOkWhenInsertOperationSucceeded()
        {
            var validationMock = new Mock <IValidator <SampleEntity> >();
            var loggerMock     = new Mock <ILogger>();
            var repositoryMock = new Mock <IRepository <SampleEntity> >();
            var requestObject  = new SampleEntity();

            loggerMock.Setup(v => v.Error(It.IsAny <string>()));
            repositoryMock.Setup(v => v.Create(requestObject)).Returns(1);
            repositoryMock.Setup(v => v.Read(1)).Returns(new SampleEntity()
            {
                ID = 1
            });
            var service = new SampleService(loggerMock.Object, repositoryMock.Object);

            // When
            var result = service.Create(requestObject);

            // Then
            Assert.True(result.IsSuccessed);
            Assert.AreEqual(1, result.Data.ID);
        }