public async Task Should_update_existing_endpoint_with_defence_advocate()
        {
            var conference1 = new ConferenceBuilder()
                              .WithEndpoint("DisplayName", "*****@*****.**").Build();
            var seededConference = await TestDataManager.SeedConference(conference1);

            var ep              = conference1.Endpoints.First();
            var sipAddress      = ep.SipAddress;
            var defenceAdvocate = "Sol Defence";

            TestContext.WriteLine($"New seeded conference id: {seededConference.Id}");
            _newConferenceId = seededConference.Id;

            var command = new UpdateEndpointCommand(_newConferenceId, sipAddress, null, defenceAdvocate);
            await _handler.Handle(command);

            Conference updatedConference;

            await using (var db = new VideoApiDbContext(VideoBookingsDbContextOptions))
            {
                updatedConference = await db.Conferences.Include(x => x.Endpoints)
                                    .AsNoTracking().SingleAsync(x => x.Id == _newConferenceId);
            }

            var updatedEndpoint = updatedConference.GetEndpoints().Single(x => x.SipAddress == sipAddress);

            updatedEndpoint.DisplayName.Should().Be(ep.DisplayName);
            updatedEndpoint.DefenceAdvocate.Should().Be(defenceAdvocate);
        }
Beispiel #2
0
        public ICommandResult Handle(UpdateEndpointCommand command)
        {
            // Fail Fast Validation
            command.Validate();
            if (command.Invalid)
            {
                return(new GenericCommandResult(false, "Dados inválidos. Verifique o preenchimento dos campos e tente novamente.", command.Notifications));
            }

            // Recupera Entidade (para reidratação)
            var endpoint = _repository.GetBySerialNumber(command.SerialNumber);

            if (endpoint == null)
            {
                return(new GenericCommandResult(false, "Nenhum Endpoint encontrado com esse Número Serial.", null));
            }

            // Altera a Entidade (reidradação)
            endpoint.Update(command.SwitchState);

            // Checa as Notificações
            if (Invalid)
            {
                return(new GenericCommandResult(false, "Dados inválidos. Verifique o preenchimento dos campos e tente novamente.", Notifications));
            }

            // Salva as Informações
            _repository.Update(endpoint);

            // Retorna as Informações
            return(new GenericCommandResult(true, "Atualização realizada com sucesso.", endpoint));
        }
        public void Should_throw_conference_not_found_exception_when_conference_does_not_exist()
        {
            var conferenceId = Guid.NewGuid();
            var displayName  = "new endpoint";
            var command      = new UpdateEndpointCommand(conferenceId, "*****@*****.**", displayName, null);

            Assert.ThrowsAsync <ConferenceNotFoundException>(() => _handler.Handle(command));
        }
        public GenericCommandResult Put(string route, UpdateEndpointCommand command)
        {
            HttpResponseMessage response = _http.PutAsync(
                $"{Settings.API_URL}/{route}",
                new StringContent(JsonConvert.SerializeObject(command), Encoding.UTF8, "application/json")).Result;
            string content = response.Content.ReadAsStringAsync().Result;
            GenericCommandResult result = JsonConvert.DeserializeObject <GenericCommandResult>(content);

            return(result);
        }
        public async Task Should_throw_exception_when_endpoint_does_not_exist()
        {
            var seededConference = await TestDataManager.SeedConference();

            var displayName = "new endpoint";

            TestContext.WriteLine($"New seeded conference id: {seededConference.Id}");
            _newConferenceId = seededConference.Id;
            var command = new UpdateEndpointCommand(_newConferenceId, "*****@*****.**", displayName, null);

            Assert.ThrowsAsync <EndpointNotFoundException>(async() => await _handler.Handle(command));
        }
        public async Task <IActionResult> UpdateDisplayNameForEndpointAsync(Guid conferenceId, string sipAddress,
                                                                            [FromBody] UpdateEndpointRequest request)
        {
            _logger.LogDebug(
                "Attempting to update endpoint {sipAddress} with display name {DisplayName}", sipAddress, request.DisplayName);

            var command = new UpdateEndpointCommand(conferenceId, sipAddress, request.DisplayName, request.DefenceAdvocate);
            await _commandHandler.Handle(command);

            if (!string.IsNullOrWhiteSpace(request.DisplayName))
            {
                await UpdateDisplayNameInKinly(conferenceId);
            }

            _logger.LogDebug(
                "Successfully updated endpoint {sipAddress} with display name {DisplayName}", sipAddress, request.DisplayName);
            return(Ok());
        }
Beispiel #7
0
        static void Update()
        {
            Console.WriteLine("Digite o Número Serial");
            var serialNumber = Console.ReadLine();

            Console.WriteLine();

            Console.WriteLine("Digite o Estado");
            Console.WriteLine();
            Console.WriteLine("0 - Desconectado");
            Console.WriteLine("1 - Conectado");
            Console.WriteLine("2 - Armado");
            var switchState = Console.ReadLine();

            Console.WriteLine();

            UpdateEndpointCommand command = new UpdateEndpointCommand(
                serialNumber,
                (EEndpointState)Enum.GetValues(typeof(EEndpointState)).GetValue(int.Parse(switchState.ToString())));

            GenericCommandResult result = _service.Put("v1/endpoints", command);

            Console.WriteLine(result.Message);
        }
Beispiel #8
0
 public UpdateEndpointHanlderTests()
 {
     _endpointRepository    = new EndpointFakeRepository();
     _endpointHandler       = new EndpointHandler(_endpointRepository);
     _updateEndpointCommand = new UpdateEndpointCommand("1", EEndpointState.Connected);
 }
 public GenericCommandResult Put(
     [FromBody] UpdateEndpointCommand command,
     [FromServices] EndpointHandler handler)
 {
     return((GenericCommandResult)handler.Handle(command));
 }