Example #1
0
 public EndpointConsole(Stories.Interfaces.IEndpointPersistence endpointPersistence)
 {
     this.createEndpoint   = new CreateEndpoint(endpointPersistence);
     this.listAllEndpoints = new ListAllEndpoints(endpointPersistence);
     this.validateSerialNumberOfEndpoint = new ValidateSerialNumberOfEndpoint(endpointPersistence);
     this.searchBySerialNumber           = new SearchBySerialNumber(endpointPersistence);
     this.editStateEndpoint = new EditStateEndpoint(endpointPersistence);
     this.deleteEndpoint    = new DeleteEndpoint(endpointPersistence);
 }
Example #2
0
            public void Validate_Serial_Validates(CreateEndpoint command, CreateEndpointValidator subject)
            {
                // Arrange

                // Act
                var result = subject.TestValidate(command);

                // Assert
                result.ShouldNotHaveAnyValidationErrors();
            }
Example #3
0
        public void MustCreateAendpoint()
        {
            //arrange
            PersistenceMock persistenceMock = new PersistenceMock();
            var             createEndpoint  = new CreateEndpoint(persistenceMock.CreateEndpoint());

            //action

            createEndpoint.Execute(ModelsMock.EndpointMock());

            //assert
            Assert.Empty(createEndpoint.Error);
        }
Example #4
0
            public async Task Handle_ValidRequest_StoresIntoContext(
                [Frozen] LandisGyrContext context,
                CreateEndpoint command,
                CreateEndpointHandler subject
                )
            {
                // Arrange

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

                // Assert
                result.Should().NotBeNull();
                result.Should().BeEquivalentTo(command);
                context.Endpoints.Should().Contain(result);
            }
Example #5
0
        private async Task CreateEndpoint(CancellationToken cancellationToken)
        {
            CreateEndpoint command = new CreateEndpoint();

            Console.Write("Insira o número serial do Endpoint: ");
            command.SerialNumber = Console.ReadLine();
            Console.Write("Insira o id do modelo do medidor do Endpoint: ");
            command.MeterModel = (MeterModels)int.Parse(Console.ReadLine());
            Console.Write("Insira o número do medidor do Endpoint: ");
            command.MeterNumber = int.Parse(Console.ReadLine());
            Console.Write("Insira a versão do firmware do medidor do Endpoint: ");
            command.MeterFirmwareVersion = Console.ReadLine();
            Console.Write("Insira o estado do switch do Endpoint: ");
            command.SwitchState = (SwitchStates)int.Parse(Console.ReadLine());

            CreateEndpointValidator validator = new CreateEndpointValidator();
            var validation = validator.Validate(command);

            if (!validation.IsValid)
            {
                Console.WriteLine(validation.Errors.FirstOrDefault());
            }
            else
            {
                try
                {
                    await _mediator.Send(command, cancellationToken);
                }
                catch (InvalidOperationException)
                {
                    Console.WriteLine($"Já existe um Endpoint com o número serial {command.SerialNumber}.");
                }
                catch (Exception)
                {
                    Console.WriteLine("Um erro inesperado ocorreu");
                }
            }
            Console.WriteLine("-------------------------------------");
        }