Пример #1
0
        public async Task SetEndpoint(Endpoint newEndpoint)
        {
            Events.SetEndpoint(this);

            try
            {
                Preconditions.CheckNotNull(newEndpoint);
                Preconditions.CheckArgument(newEndpoint.Id.Equals(this.Endpoint.Id), $"Can only set new endpoint with same id. Given {newEndpoint.Id}, expected {this.Endpoint.Id}");

                if (this.closed)
                {
                    throw new InvalidOperationException($"Endpoint executor for endpoint {this.Endpoint} is closed.");
                }

                UpdateEndpoint command = Commands.UpdateEndpoint(newEndpoint);
                await this.machine.RunAsync(command);

                Events.SetEndpointSuccess(this);
            }
            catch (Exception ex)
            {
                Events.SetEndpointFailure(this, ex);
                throw;
            }
        }
        public async Task should_fail_when_endpoint_not_found()
        {
            var endpoint = new Mongo.Infrastructure.Entities.ServiceEndpoint()
            {
                Id       = Guid.NewGuid(),
                Address  = "ipsum",
                Protocol = "dolor",
                Active   = false
            };
            var service = new Mongo.Infrastructure.Entities.Service()
            {
                Id        = Guid.NewGuid(),
                Active    = false,
                Name      = "lorem",
                Endpoints = new[] { endpoint }
            };
            var mockRepo = RepositoryUtils.MockRepository <Mongo.Infrastructure.Entities.Service>(service);

            var mockDbContext = new Mock <IDbContext>();

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

            var command = new UpdateEndpoint(service.Id, Guid.NewGuid(), endpoint.Protocol, endpoint.Address);
            var sut     = new UpdateEndpointValidator(mockDbContext.Object);
            var result  = await sut.ValidateAsync(command);

            result.Success.Should().BeFalse();
            result.Errors.Any(e => e.Context == "endpoint" && e.Message.Contains(command.EndpointId.ToString())).Should().BeTrue();
        }
Пример #3
0
        public void testUpdateMsg()
        {
            withContext(context =>
            {
                UpdateEndpointV0_6 testProtocol = UpdateEndpoint.v0_6();
                JsonObject msg = testProtocol.updateMsg(context);

                Assert.AreEqual(
                    msg.getAsJsonObject("comMethod").getAsString("value"),
                    context.EndpointUrl()
                    );
                Assert.AreEqual(
                    "did:sov:123456789abcdefghi1234;spec/configs/0.6/UPDATE_COM_METHOD",
                    msg.getAsString("@type")
                    );
                Assert.IsNotNull(msg.getAsString("@id"));
                Assert.AreEqual("webhook", msg.getAsJsonObject("comMethod").getAsString("id"));
                Assert.AreEqual(2, msg.getAsJsonObject("comMethod").getAsInteger("type"));
                Assert.AreEqual(
                    "1.0",
                    msg.getAsJsonObject("comMethod").getAsJsonObject("packaging").getAsString("pkgType")
                    );
                List <string> expectedReceipientKeys = new List <string>();
                expectedReceipientKeys.Add(context.SdkVerKey());

                var rcp = msg.getAsJsonObject("comMethod").getAsJsonObject("packaging").getAsJsonArray("recipientKeys").Select(s => s.ToString().Trim('"')).ToList();
                Assert.IsTrue(expectedReceipientKeys.EquivalentTo(rcp));
            });
        }
Пример #4
0
        void updateWebhookEndpoint()
        {
            string webhookFromCtx = "";

            try
            {
                webhookFromCtx = context.EndpointUrl();
            }
            catch (UndefinedContextException ignored)
            {
                var s = ignored.Message; // Fix build warning
            }

            string webhook = consoleInput($"Ngrok endpoint for [port:{listenerPort}]", Environment.GetEnvironmentVariable("WEBHOOK_URL")).Trim();

            if ("".Equals(webhook))
            {
                webhook = webhookFromCtx;
            }

            App.coloredConsoleOutput(webhook, "Using Webhook: ");
            context = context.ToContextBuilder().endpointUrl(webhook).build();

            // request that verity-application use specified webhook endpoint
            UpdateEndpoint.v0_6().update(context);
        }
Пример #5
0
            public void Validate_ValidCommand_Returns(UpdateEndpoint command, UpdateEndpointValidator subject)
            {
                // Arrange

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

                // Assert
                result.ShouldNotHaveAnyValidationErrors();
            }
Пример #6
0
        public void testGetMessageType()
        {
            UpdateEndpointV0_6 testProtocol = UpdateEndpoint.v0_6();
            string             msgName      = "msg name";

            Assert.AreEqual(
                Util.getMessageType(Util.EVERNYM_MSG_QUALIFIER, testProtocol.family(), testProtocol.version(), msgName),
                testProtocol.messageType(msgName)
                );
        }
Пример #7
0
 public void testUpdate()
 {
     withContext(context =>
     {
         UpdateEndpointV0_6 testProtocol = UpdateEndpoint.v0_6();
         byte[] message             = testProtocol.updateMsgPacked(context);
         JsonObject unpackedMessage = TestHelpers.unpackForwardMessage(context, message);
         Assert.AreEqual(
             Util.EVERNYM_MSG_QUALIFIER + "/configs/0.6/UPDATE_COM_METHOD",
             unpackedMessage.getAsString("@type")
             );
     });
 }
Пример #8
0
 public void testUpdate()
 {
     withContext(context =>
     {
         UpdateEndpointV0_6 testProtocol = UpdateEndpoint.v0_6();
         byte[] message             = testProtocol.updateMsgPacked(context);
         JsonObject unpackedMessage = TestHelpers.unpackForwardMessage(context, message);
         Assert.AreEqual(
             "did:sov:123456789abcdefghi1234;spec/configs/0.6/UPDATE_COM_METHOD",
             unpackedMessage.getAsString("@type")
             );
     });
 }
        public AgentApp()
        {
            AgentPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Battle.net", "Agent", "Agent.exe");

            StartProcess();

            AgentEndpoint   = new AgentEndpoint(Requester);
            InstallEndpoint = new InstallEndpoint(Requester);
            UpdateEndpoint  = new UpdateEndpoint(Requester);
            RepairEndpoint  = new RepairEndpoint(Requester);
            GameEndpoint    = new GameEndpoint(Requester);
            VersionEndpoint = new VersionEndpoint(Requester);
        }
Пример #10
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>();
            }
Пример #11
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));
        }
Пример #12
0
        public AgentApp()
        {
            AgentPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Battle.net", "Agent", "Agent.exe");

            if (!StartProcess())
            {
                Console.WriteLine("Please ensure Battle.net is installed and has recently been opened.");
                Environment.Exit(0);
            }

            AgentEndpoint   = new AgentEndpoint(Requester);
            InstallEndpoint = new InstallEndpoint(Requester);
            UpdateEndpoint  = new UpdateEndpoint(Requester);
            RepairEndpoint  = new RepairEndpoint(Requester);
            GameEndpoint    = new GameEndpoint(Requester);
            VersionEndpoint = new VersionEndpoint(Requester);
        }
Пример #13
0
        private async Task UpdateEndpoint(CancellationToken cancellationToken)
        {
            FindEndpoint findCommand = new FindEndpoint();

            Console.Write("Insira o número serial do Endpoint: ");
            findCommand.SerialNumber = Console.ReadLine();

            var result = await _mediator.Send(findCommand, cancellationToken);

            if (result is null)
            {
                Console.WriteLine($"Não existe um Endpoint com número serial {findCommand.SerialNumber}");
            }
            else
            {
                UpdateEndpoint updateCommand = new UpdateEndpoint();

                Console.Write("Insira o estado do switch do Endpoint: ");
                updateCommand.SwitchState  = (SwitchStates)int.Parse(Console.ReadLine());
                updateCommand.SerialNumber = findCommand.SerialNumber;

                UpdateEndpointValidator validator = new UpdateEndpointValidator();
                var validation = validator.Validate(updateCommand);

                if (!validation.IsValid)
                {
                    Console.WriteLine(validation.Errors.FirstOrDefault());
                }
                else
                {
                    try
                    {
                        await _mediator.Send(updateCommand, cancellationToken);
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("Um erro inesperado ocorreu");
                    }
                }
            }
            Console.WriteLine("-------------------------------------");
        }
Пример #14
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());
        }
Пример #15
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();
            }
        public async Task should_fail_when_service_has_no_endpoints()
        {
            var service = new Mongo.Infrastructure.Entities.Service()
            {
                Id        = Guid.NewGuid(),
                Active    = false,
                Name      = "lorem",
                Endpoints = Enumerable.Empty <Mongo.Infrastructure.Entities.ServiceEndpoint>()
            };
            var mockRepo = RepositoryUtils.MockRepository <Mongo.Infrastructure.Entities.Service>(service);

            var mockDbContext = new Mock <IDbContext>();

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

            var command = new UpdateEndpoint(service.Id, Guid.NewGuid(), "lorem", "ipsum");
            var sut     = new UpdateEndpointValidator(mockDbContext.Object);
            var result  = await sut.ValidateAsync(command);

            result.Success.Should().BeFalse();
            result.Errors.Any(e => e.Context == "service" && e.Message.Contains(service.Id.ToString())).Should().BeTrue();
        }
Пример #17
0
        public void testGetThreadId()
        {
            UpdateEndpointV0_6 testProtocol = UpdateEndpoint.v0_6();

            Assert.IsNotNull(testProtocol.getThreadId());
        }