예제 #1
0
        public async Task should_fail_when_command_null()
        {
            var mockDbContext = new Mock <IDbContext>();
            var mockValidator = new Mock <IValidator <UpdateEndpoint> >();

            var sut = new UpdateEndpointHandler(mockDbContext.Object, mockValidator.Object);
            await Assert.ThrowsAsync <ArgumentNullException>(() => sut.Handle(null));
        }
예제 #2
0
            public async Task Handle_NullCommand_ThrowsArgumentNullException(
                UpdateEndpointHandler subject
                )
            {
                // Arrange

                // Act
                Func <Task> act = () => subject.Handle(null, default);

                // Assert
                await act.Should().ThrowExactlyAsync <ArgumentNullException>();
            }
예제 #3
0
            public async Task Handle_EndpointNotFound_ThrowsKeyNotFoundException(
                UpdateEndpoint command,
                UpdateEndpointHandler subject
                )
            {
                // Arrange

                // Act
                Func <Task> act = () => subject.Handle(command, default);

                // Assert
                await act.Should().ThrowExactlyAsync <KeyNotFoundException>();
            }
예제 #4
0
        public async Task should_throw_when_service_not_found()
        {
            var command = new UpdateEndpoint(Guid.NewGuid(), Guid.NewGuid(), "lorem", "ipsum");

            var mockRepo = RepositoryUtils.MockRepository <Mongo.Infrastructure.Entities.Service>();

            var mockDbContext = new Mock <IDbContext>();

            mockDbContext.Setup(db => db.Services).Returns(mockRepo.Object);

            var validator = new NullValidator <UpdateEndpoint>();

            var sut = new UpdateEndpointHandler(mockDbContext.Object, validator);
            await Assert.ThrowsAsync <NullReferenceException>(() => sut.Handle(command));
        }
예제 #5
0
        public async Task should_update_endpoint_when_command_valid_and_deactivate_it()
        {
            var command = new UpdateEndpoint(Guid.NewGuid(), Guid.NewGuid(), "lorem", "ipsum");

            var service = new Mongo.Infrastructure.Entities.Service()
            {
                Id        = command.ServiceId,
                Active    = false,
                Endpoints = new[]
                {
                    new Mongo.Infrastructure.Entities.ServiceEndpoint()
                    {
                        Id       = command.EndpointId,
                        Active   = true,
                        Address  = "localhost",
                        Protocol = "http"
                    }
                }
            };

            var mockRepo = RepositoryUtils.MockRepository(service);

            var mockDbContext = new Mock <IDbContext>();

            mockDbContext.Setup(db => db.Services).Returns(mockRepo.Object);

            var validator = new NullValidator <UpdateEndpoint>();

            var sut = new UpdateEndpointHandler(mockDbContext.Object, validator);
            await sut.Handle(command);

            mockRepo.Verify(m => m.UpsertOneAsync(It.IsAny <Expression <Func <Mongo.Infrastructure.Entities.Service, bool> > >(),
                                                  It.Is <Mongo.Infrastructure.Entities.Service>(r =>
                                                                                                r.Id == command.ServiceId &&
                                                                                                r.Active == false &&
                                                                                                null != r.Endpoints && 1 == r.Endpoints.Count() &&
                                                                                                r.Endpoints.Any(es => es.Active == false &&
                                                                                                                es.Id == command.EndpointId &&
                                                                                                                es.Address == command.Address &&
                                                                                                                es.Protocol == command.Protocol))
                                                  ), Times.Once());
        }
예제 #6
0
            public async Task Handle_EndpointFound_Returns(
                Endpoint endpoint,
                UpdateEndpoint command,
                [Frozen] LandisGyrContext context,
                UpdateEndpointHandler subject
                )
            {
                // Arrange
                context.Endpoints.Add(endpoint);
                await context.SaveChangesAsync();

                command.SerialNumber = endpoint.SerialNumber;
                command.SwitchState  = endpoint.SwitchState;

                // Act
                var result = await subject.Handle(command, default);

                // Assert
                result.Should().NotBeNull();
            }