public static ClientCard ConvertToClientCard(ClientCardFromBody client) { if (client == null) { throw new EntitiesException("Input can not be null"); } return(new ClientCard { Id = Guid.NewGuid(), ContractId = client.ContractId, ClientName = client.ClientName.Trim(), ClientAddress = client.ClientAddress.Trim(), PhoneNumber = client.PhoneNumber.Trim(), Email = client.Email.Trim(), Equipment = client.Equipment.Trim(), Breakage = client.Breakage.Trim(), MasterName = client.MasterName.Trim(), MasterPersonnelNumber = client.MasterPersonnelNumber.Trim(), PutDate = CheckDate(client.PutDate), PerformDate = CheckDate(client.PerformDate), Works = ConvertToWorks(client.WorkList), RepairEquipments = ConvertToRepairEquipment(client.RepairEquipments) }); }
public void GetOrderClientCards() { var clientCardFromBody2 = new ClientCardFromBody( "2", "Антон", "ЕКБ", "8", "*****@*****.**", "TV", "Display", "Sergey", "123", new DateTime(2018, 01, 01), new DateTime(2018, 01, 01), new string[] { "sr" }, new string[][] { new string[] { "resistor1", "10" }, new string[] { "resistor2", "15" } }); var options = SetOptions("Get_order_client_card"); var dbService = new ClientCardDatabaseService(options); var clientCard2 = ClientCard.ConvertToClientCard(clientCardFromBody2); var clientCard = ClientCard.ConvertToClientCard(ClientCardFromBody); var context = new ClientCardContext(options); dbService.AddClientCardWithContext(clientCard2, context); dbService.AddClientCardWithContext(clientCard, context); var db = dbService.GetAllClientCardsWithContext(context); db.First().ContractId.Should().Be(1); }
public void CanNotConvertNullToCardClient() { ClientCardFromBody clientFromBody = null; Action act = () => ClientCard.ConvertToClientCard(clientFromBody); act.Should().Throw <EntitiesException>() .WithMessage("Input can not be null"); }
public IActionResult Save([FromBody] ClientCardFromBody clientCardFromBody) { try { var clientCard = ClientCard.ConvertToClientCard(clientCardFromBody); var xmlData = ClientCardSerializeService.SerializeDataToXml(clientCard, this.encode); var bytes = this.encode.GetBytes(xmlData); return(this.File(bytes, "application/otcet-stream", "client.xml")); } catch (EntitiesException ex) { return(this.StatusCode(406, ex.Message)); } }
public void CanNotPutDateYearOverThreeThousand() { var clientFromBody = new ClientCardFromBody( "1", "Антон", "ЕКБ", "8", "*****@*****.**", "TV", "Display", "Sergey", "123", new DateTime(3050, 01, 01), new DateTime(2018, 03, 01), new[] { "sr" }, new[] { new[] { "resistor1", "10" }, new[] { "resistor2", "15" } }); Action act = () => ClientCard.ConvertToClientCard(clientFromBody); act.Should().Throw <EntitiesException>() .WithMessage("Invalid year"); }
public void CanNotConvertToCardClientWithoutWorks() { var clientFromBody = new ClientCardFromBody( "1", "Антон", "ЕКБ", "8", "*****@*****.**", "TV", "Display", "Sergey", "123", new DateTime(2018, 01, 01), new DateTime(2018, 03, 01), new string[] { }, new[] { new[] { "resistor1", "10" }, new[] { "resistor2", "15" } }); Action act = () => ClientCard.ConvertToClientCard(clientFromBody); act.Should().Throw <EntitiesException>() .WithMessage("Works can not be null"); }
public IActionResult SaveDatabase([FromBody] ClientCardFromBody clientCardFromBody) { ClientCard clientCard; try { clientCard = ClientCard.ConvertToClientCard(clientCardFromBody); } catch (EntitiesException ex) { return(this.StatusCode(406, ex.Message)); } try { this.dbService.AddClientCardWithContext(clientCard, this.context); return(this.Ok("Saved")); } catch (DatabaseException ex) { return(this.StatusCode(208, ex.Message)); } }
public void ConvertToClientCardFromBodyTest() { var clientFromBody = ClientCardFromBody.ConvertToClientCardFromBody(this.client); clientFromBody.Should().BeEquivalentTo(this.clientCardFromBody); }