Ejemplo n.º 1
0
        public void UpdateCallStatus_CallNull_ReceiverSid()
        {
            // Setup dependence
            var settingMock = new Mock<ISettings>();
            var componentMock = new Mock<IComponents>();
            var uowMock = new Mock<IUnitOfWork>();
            var repositoryMock = new Mock<IRepository>();
            var serviceLocatorMock = new Mock<IServiceLocator>();

            serviceLocatorMock.Setup(r => r.GetInstance<IRepository>())
                .Returns(repositoryMock.Object);
            ServiceLocator.SetLocatorProvider(() => serviceLocatorMock.Object);
            // Arrange data
            string receiverSid = "12345";
            string status = "queued";
            Call call = new Call
            {
                Id = Guid.NewGuid(),
                ReceiverSid = string.Empty
            };
            Call[] calls = new Call[] { call };
            repositoryMock.Setup(r => r.Query<Call>()).Returns(calls.AsQueryable());

            // Act
            CallService callService = new CallService(uowMock.Object, repositoryMock.Object, settingMock.Object, componentMock.Object);
            CallDto currentCall = callService.UpdateCallStatus(receiverSid, status);

            // Assert
            Assert.AreEqual(currentCall, null);
        }
Ejemplo n.º 2
0
        public void UpdateCallStatus_CallNotNull_CallSid()
        {
            // 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
            string callSid = "12345";
            string callerStatus = "queued";
            Call call = new Call
            {
                Id = Guid.NewGuid(),
                CallerSid = callSid
            };
            Call[] calls = new Call[] { call };
            repositoryMock.Setup(r => r.Query<Call>()).Returns(calls.AsQueryable());

            // Act
            CallService callService = new CallService(uowMock.Object, repositoryMock.Object, settingMock.Object, componentMock.Object);
            CallDto currentCall = callService.UpdateCallStatus(callSid, callerStatus);

            // Assert
            repositoryMock.Verify(r => r.Query<Call>());
            uowMock.Verify(u => u.Save());
            Assert.AreEqual(currentCall.CallerStatus, callerStatus);
        }
Ejemplo n.º 3
0
        public void GetByBookingId_AnyIds()
        {
            // Setup dependence
            var settingMock = new Mock<ISettings>();
            var componentMock = new Mock<IComponents>();
            var uowMock = new Mock<IUnitOfWork>();
            var repositoryMock = new Mock<IRepository>();
            var serviceLocatorMock = new Mock<IServiceLocator>();

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

            // Arrange data
            Guid id = Guid.NewGuid();
            Call call = new Call
            {
                Id = Guid.NewGuid(),
                Booking = new Booking
                {
                    Id = id
                }
            };
            Call[] calls = new Call[] { call };
            repositoryMock.Setup(r => r.Query<Call>()).Returns(calls.AsQueryable());

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

            // Assert
            repositoryMock.Verify(r => r.Query<Call>());
        }
Ejemplo n.º 4
0
        public void GetCallInProgressByCallerId_AnyIds_CallerStatusQueued()
        {
            // Setup dependence
            var settingMock = new Mock<ISettings>();
            var componentMock = new Mock<IComponents>();
            var uowMock = new Mock<IUnitOfWork>();
            var repositoryMock = new Mock<IRepository>();
            var serviceLocatorMock = new Mock<IServiceLocator>();

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

            // Arrange data
            Guid id = Guid.NewGuid();
            string callerStatus = "queued";
            Call call = new Call
            {
                Id = Guid.NewGuid(),
                CallerStatus = callerStatus,
                Caller = new User { Id = id }
            };
            Call[] calls = new Call[] { call };
            repositoryMock.Setup(r => r.Query<Call>()).Returns(calls.AsQueryable());

            // Act
            CallService callService = new CallService(uowMock.Object, repositoryMock.Object, settingMock.Object, componentMock.Object);
            var currentCall = callService.GetCallByCallerIdAndStatus(id, callerStatus);

            // Assert
            Assert.AreEqual(call.Caller.Id, currentCall.Caller.Id);
        }
        public void RatingCalculator_GuidId()
        {
            var settingsMock = new Mock<ISettings>();
            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();
            User user = new User { Id = id };

            Booking booking = new Booking
            {
                Id = Guid.NewGuid(),
                Specialist = user
            };

            Call call1 = new Call
            {
                Id = Guid.NewGuid(),
                Booking = booking,
                Rating = 2
            };
            Call call2 = new Call
            {
                Id = Guid.NewGuid(),
                Booking = booking,
                Rating = 4
            };

            User[] users = new User[] { user };
            repositoryMock.Setup(r => r.Query<User>()).Returns(users.AsQueryable());

            Booking[] bookings = new Booking[] { booking };
            repositoryMock.Setup(r => r.Query<Booking>()).Returns(bookings.AsQueryable());

            Call[] calls = new Call[] { call1, call2 };
            repositoryMock.Setup(r => r.Query<Call>()).Returns(calls.AsQueryable());

            double expectedValue = 3;

            // Act
            var bookingService = new BookingService(uowMock.Object, repositoryMock.Object, settingsMock.Object);
            double currentValue = bookingService.RatingCalculator(id);

            // Assert
            repositoryMock.Verify(r => r.Query<Call>());//.Where(c=>c.Booking.Specialist.Id == id));
            Assert.AreEqual(expectedValue, currentValue);
        }