public async Task handler_should_throw_exception_with_existing_device() { var command = new CreateDevice { Id = "device1", Enabled = true, Password = "******" }; var userName = "******"; var httpContext = new DefaultHttpContext(); var user = new System.Security.Claims.ClaimsPrincipal(); user.AddIdentity(new System.Security.Claims.ClaimsIdentity(new List <Claim> { new Claim(ClaimTypes.Name, userName) })); httpContext.User = user; _httpContextAccessor.HttpContext.Returns(httpContext); var account = new Account() { Id = Guid.NewGuid() }; _accountRepository.GetByUserName(userName).Returns(account); _deviceRepository.Get(command.Id).Returns(new Device()); Should.Throw <DeviceAlreadyExistsException>(() => _handler.Handle(command, new System.Threading.CancellationToken())); }
private void btnPrim_Click(object sender, EventArgs e) { var button = sender as ToolStripButton; if (button != null) { var devTypeName = button.Tag.ToString(); CreateDevice?.Invoke(devTypeName); } }
public async Task handler_should_throw_exception_with_empty_device_password() { var command = new CreateDevice { Id = "asd", Enabled = true, Password = "" }; Should.Throw <DevicePasswordEmptyException>(() => _handler.Handle(command, new System.Threading.CancellationToken())); }
public JsonResult CreateDevice(CreateDevice device) { if (ModelState.IsValid) { Status status = new DeviceService().create(device); return(Json(new RespondModel(status, ""), JsonRequestBehavior.AllowGet)); } return(Json(new RespondModel(Status.ARGUMENT_ERROR, ModelStateHelper.errorMessages(ModelState)), JsonRequestBehavior.AllowGet)); }
internal static ButtplugFFIDeviceHandle SendCreateDevice(ButtplugFFIClientHandle aHandle, uint aDeviceIndex) { var builder = new FlatBufferBuilder(128); CreateDevice.StartCreateDevice(builder); CreateDevice.AddIndex(builder, aDeviceIndex); var get_device_msg = CreateDevice.EndCreateDevice(builder); builder.Finish(get_device_msg.Value); var buf = builder.SizedByteArray(); return(ButtplugFFICalls.buttplug_create_device(aHandle, buf, buf.Length)); }
public void AddDevice() { TYPE type = UserTypeSelector(); string ID = AskID(); string name = AskName(); DateTime warranty = AskDateTime(); double price = AskPrice(); CreateDevice createGivenDevice = CreateCustomDeviceDelegate(type); Devices.Add(createGivenDevice(type, ID, name, warranty, price)); Console.Clear(); Console.WriteLine("New {0} was successfully added!", type.ToString().ToLower()); Thread.Sleep(2000); }
private async Task StartDevice() { await Task.Run(() => { var request = new CreateDevice { Id = Id, Type = (DeviceType)Enum.Parse(typeof(DeviceType), cType.SelectedItem.ToString()), Minimum = (int)nMinimum.Value, Maximum = (int)nMaximum.Value, Interval = (int)nInterval.Value, }; Store.Dispatch(request); Store.Dispatch(new StartDevice { DeviceId = Id }); }); }
public async Task post_device_should_create_device() { var request = new CreateDevice { Id = "device3", Enabled = true, Password = "******" }; var resp = await PostAsync("/devices", request); resp.ShouldNotBeNull(); resp.StatusCode.ShouldBe(System.Net.HttpStatusCode.Created); var createdHeader = resp.Headers.Location; var locationString = createdHeader.OriginalString; var dto = await GetAsync <DeviceDto>(locationString); dto.ShouldNotBeNull(); dto.Id.ShouldBe(request.Id); }
public async Task handler_should_create_device_with_correct_data() { var command = new CreateDevice { Id = "device1", Enabled = true, Password = "******" }; var userName = "******"; var httpContext = new DefaultHttpContext(); var user = new System.Security.Claims.ClaimsPrincipal(); user.AddIdentity(new System.Security.Claims.ClaimsIdentity(new List <Claim> { new Claim(ClaimTypes.Name, userName) })); httpContext.User = user; _httpContextAccessor.HttpContext.Returns(httpContext); var account = new Account() { Id = Guid.NewGuid() }; _accountRepository.GetByUserName(userName).Returns(account); _deviceRepository.Get(command.Id).Returns((Device)null); await _handler.Handle(command, new System.Threading.CancellationToken()); await _deviceRepository.Received().Create(Arg.Is <Device>(d => d.Id == command.Id && d.Enabled == command.Enabled)); await _accountDeviceRepository.Received().Create(Arg.Is <AccountDevice>(ad => ad.DeviceId == command.Id && ad.AccountId == account.Id)); await _hiveMqCredentialsService.Received().AddCredentials(command.Id, command.Password); }
public async Task <ActionResult> Post(CreateDevice command) { await _mediator.Send(command); return(Created($"/devices/{command.Id}", null)); }
static void Main() { CreateDevice frm = new CreateDevice(); Application.Run(new CreateDevice()); }
public async Task <IActionResult> Post(CreateDevice command) => await SendAsync(command.BindId(c => c.Id), resourceId : command.Id, resource : "devices");