예제 #1
0
        public void ReceiverReadyNow_AnyCallIds_CallNull()
        {
            // Setup dependence
            var settingMock = new Mock<ISettings>();
            var componentMock = new Mock<IComponents>();
            var repositoryMock = new Mock<IRepository>();
            var uowMock = new Mock<IUnitOfWork>();
            var serviceLocatorMock = new Mock<IServiceLocator>();

            serviceLocatorMock.Setup(r => r.GetInstance<IRepository>())
                .Returns(repositoryMock.Object);
            ServiceLocator.SetLocatorProvider(() => serviceLocatorMock.Object);

            // Arrange data
            Guid id = Guid.NewGuid();

            // Act
            CallService callService = new CallService(uowMock.Object, repositoryMock.Object, settingMock.Object, componentMock.Object);
            CallDto currentCall = callService.ReceiverReadyNow(id);

            // Assert
            repositoryMock.Verify(r => r.FindById<Call>(id));
            Assert.AreEqual(null, currentCall);
        }
예제 #2
0
        public void ReceiverReadyNow_AnyCallIds()
        {
            // Setup dependence
            var settingMock = new Mock<ISettings>();
            var componentMock = new Mock<IComponents>();
            var repositoryMock = new Mock<IRepository>();
            var uowMock = new Mock<IUnitOfWork>();
            var serviceLocatorMock = new Mock<IServiceLocator>();

            serviceLocatorMock.Setup(r => r.GetInstance<IRepository>())
                .Returns(repositoryMock.Object);
            serviceLocatorMock.Setup(r => r.GetInstance<IUnitOfWork>())
                .Returns(uowMock.Object);
            ServiceLocator.SetLocatorProvider(() => serviceLocatorMock.Object);
            repositoryMock.Setup(r => r.CreateUnitOfWork()).Returns(uowMock.Object);

            // Arrange data
            Guid id = Guid.NewGuid();
            bool expectedResult = true;
            Call call = new Call
            {
                Id = id
            };
            repositoryMock.Setup(r => r.FindById<Call>(id)).Returns(call);

            // Act
            CallService callService = new CallService(uowMock.Object, repositoryMock.Object, settingMock.Object, componentMock.Object);
            CallDto currentCall = callService.ReceiverReadyNow(id);

            // Assert
            repositoryMock.Verify(r => r.FindById<Call>(id));
            repositoryMock.Verify(r => r.Update<Call>(It.IsAny<Call>()));
            uowMock.Verify(u => u.Save());
            Assert.AreEqual(expectedResult, currentCall.ReceiverReady);
        }