Esempio n. 1
0
        private async Task <Endpoint> CreateInternalEndpointAsync(Endpoint endpoint, CancellationToken cancelToken)
        {
            _context.Endpoints.Add(endpoint);

            await _context.SaveChangesAsync(cancelToken);

            return(endpoint);
        }
Esempio n. 2
0
            public async Task Handle_EndpointExists_ReturnsUnit(
                [Frozen] LandisGyrContext context,
                Endpoint endpoint,
                DeleteEndpointHandler subject)
            {
                // Arrange
                context.Endpoints.Add(endpoint);
                await context.SaveChangesAsync();

                // Act
                var result = await subject.Handle(new DeleteEndpoint { SerialNumber = endpoint.SerialNumber }, default);

                // Assert
                result.Should().NotBeNull();
                context.Endpoints.Should().BeEmpty();
            }
Esempio n. 3
0
        private async Task<Unit> DeleteEndpointInternalAsync(string serialNumber, CancellationToken cancellationToken)
        {
            var existingEndpoint = await _context
                .Endpoints
                .WithSerialNumber(serialNumber).SingleOrDefaultAsync(cancellationToken);

            if (existingEndpoint is null)
            {
                throw new KeyNotFoundException($"Não existe Endpoint para o serial number {serialNumber}.");
            }

            _context.Endpoints.Remove(existingEndpoint);
            await _context.SaveChangesAsync(cancellationToken);

            return Unit.Value;
        }
Esempio n. 4
0
            public async Task Handle_EndpointNotFound_ReturnsNull([Frozen] LandisGyrContext context,
                                                                  Endpoint endpoint,
                                                                  FindEndpointHandler subject)
            {
                // Arrange
                context.Add(endpoint);
                await context.SaveChangesAsync();

                // Act
                var result = await subject.Handle(new FindEndpoint { SerialNumber = string.Empty }, default);

                // Assert
                result
                .Should()
                .BeNull();
            }
Esempio n. 5
0
            public async Task Handle_ExistingContext_ReturnsEndpoint([Frozen] LandisGyrContext context,
                                                                     Endpoint endpoint,
                                                                     FindEndpointHandler subject)
            {
                // Arrange
                context.Add(endpoint);
                await context.SaveChangesAsync();

                // Act
                var result = await subject.Handle(new FindEndpoint { SerialNumber = endpoint.SerialNumber }, default);

                // Assert
                result
                .Should()
                .NotBeNull().And
                .BeEquivalentTo(endpoint);
            }
Esempio n. 6
0
            public async Task Handle_ExistingContext_ReturnsList([Frozen] LandisGyrContext context,
                                                                 IEnumerable <Endpoint> endpoints,
                                                                 FindAllEndpointsHandler subject)
            {
                // Arrange
                context.AddRange(endpoints);
                await context.SaveChangesAsync();

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

                // Assert
                result
                .Should()
                .NotBeNull().And
                .HaveSameCount(context.Endpoints);
            }
Esempio n. 7
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();
            }
Esempio n. 8
0
        private async Task <Unit> UpdateEndpointInternalAsync(Endpoint updatedModel, CancellationToken cancellationToken)
        {
            var existingEndpoint = await _context
                                   .Endpoints
                                   .WithSerialNumber(updatedModel.SerialNumber)
                                   .SingleOrDefaultAsync(cancellationToken);

            // TODO: Checar problema no profile <Endpoint, Endpoint> do AutoMapper
            //_mapper.Map(updatedModel, existingEndpoint);

            if (existingEndpoint is null)
            {
                throw new KeyNotFoundException($"Não existe Endpoint para o serial number {updatedModel.SerialNumber}.");
            }

            existingEndpoint.SwitchState = updatedModel.SwitchState;

            await _context.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }