public void MapToContract_MapCustomFields_CallsMapper() { var customField1 = new CustomField() { id = 123456, value = "test1" }; var customField2 = new CustomField() { id = 123457, value = "test2" }; var salesInvoice = new SalesInvoiceGet() { state = "draft", custom_fields = new List <CustomField>() { customField1, customField2 } }; _customFieldMapper.Setup(c => c.MapToContract(customField1)).Returns(new Contract.Model.CustomField()); _customFieldMapper.Setup(c => c.MapToContract(customField2)).Returns(new Contract.Model.CustomField()); _mapper.MapToContract(salesInvoice); _customFieldMapper.VerifyAll(); }
public void MapToContract_MapDetails_CallsMapper() { var salesInvoiceDetail1 = new SalesInvoiceDetail() { }; var salesInvoiceDetail2 = new SalesInvoiceDetail() { }; var salesInvoice = new SalesInvoiceGet() { state = "draft", details = new List <SalesInvoiceDetail>() { salesInvoiceDetail1, salesInvoiceDetail2 } }; var mappedDetail1 = new Contract.Model.SalesInvoiceDetail(); var mappedDetail2 = new Contract.Model.SalesInvoiceDetail(); _salesInvoiceDetailMapper.Setup(c => c.MapToContract(salesInvoiceDetail1)).Returns(mappedDetail1); _salesInvoiceDetailMapper.Setup(c => c.MapToContract(salesInvoiceDetail2)).Returns(mappedDetail2); var result = _mapper.MapToContract(salesInvoice); result.Details.Should().Contain(mappedDetail1); result.Details.Should().Contain(mappedDetail2); _salesInvoiceDetailMapper.VerifyAll(); }
public void MapToApi_MapSalesInvoiceDetails_CallsMapper() { var current = new SalesInvoiceGet(); var salesInvoiceDetail1 = new Contract.Model.SalesInvoiceDetail() { }; var salesInvoiceDetail2 = new Contract.Model.SalesInvoiceDetail() { }; var salesInvoice = new Contract.Model.SalesInvoice() { State = Contract.Model.SalesInvoiceStatus.Draft, Details = new List <Contract.Model.SalesInvoiceDetail>() { salesInvoiceDetail1, salesInvoiceDetail2 } }; var salesInvoiceDetail = new SalesInvoiceDetail(); var salesInvoiceDetai2 = new SalesInvoiceDetail(); _salesInvoiceDetailMapper.Setup(c => c.MapToApi(salesInvoiceDetail1, null)).Returns(salesInvoiceDetail); _salesInvoiceDetailMapper.Setup(c => c.MapToApi(salesInvoiceDetail2, null)).Returns(salesInvoiceDetai2); var result = _mapper.MapToApi(salesInvoice, current); result.details_attributes.Should().Contain(salesInvoiceDetail); result.details_attributes.Should().Contain(salesInvoiceDetai2); _salesInvoiceDetailMapper.VerifyAll(); }
public void Update_GetAndUpdate_CallsConnectorWithUpdate() { var salesInvoiceId = 1234; var existing = new SalesInvoiceGet() { id = salesInvoiceId, }; var data = new Contract.Model.SalesInvoice() { Id = existing.id }; var existingMapped = new SalesInvoicePost(); var saveResult = new SalesInvoiceGet(); var mappedResult = new Contract.Model.SalesInvoice() { ContactId = 1234 }; _defaultConnector.Setup(c => c.GetById(salesInvoiceId)).Returns(existing); _mapper.Setup(c => c.MapToApi(data, existing)).Returns(existingMapped); _defaultConnector.Setup(c => c.Update(salesInvoiceId, It.Is <SalesInvoiceWrapper>(v => v.sales_invoice == existingMapped))).Returns(saveResult); _mapper.Setup(c => c.MapToContract(saveResult)).Returns(mappedResult); var result = _invoiceService.Update(salesInvoiceId, data); result.Should().BeEquivalentTo(mappedResult); _defaultConnector.Verify(c => c.Update(salesInvoiceId, It.Is <SalesInvoiceWrapper>(v => v.sales_invoice == existingMapped)), Times.Once); }
public void MapToApi_MapCustomFields_CallsMapper() { var current = new SalesInvoiceGet(); var customField1 = new Contract.Model.CustomField() { Id = 123456, Value = "test1" }; var customField2 = new Contract.Model.CustomField() { Id = 123457, Value = "test2" }; var salesInvoice = new Contract.Model.SalesInvoice() { State = Contract.Model.SalesInvoiceStatus.Draft, CustomFields = new List <Contract.Model.CustomField>() { customField1, customField2 } }; _customFieldMapper.Setup(c => c.MapToApi(customField1, null)).Returns(new CustomField()); _customFieldMapper.Setup(c => c.MapToApi(customField2, null)).Returns(new CustomField()); _mapper.MapToApi(salesInvoice, current); _customFieldMapper.VerifyAll(); }
public void MapToContract_StateEnumNotExist_ThrowsException() { var salesInvoice = new SalesInvoiceGet() { state = "test" }; Action a = () => _mapper.MapToContract(salesInvoice); a.Should().Throw <Exception>(); }
public void MapToContract_MapStateEnum_Correctly(Contract.Model.SalesInvoiceStatus output, string input) { var salesInvoice = new SalesInvoiceGet() { state = input }; var result = _mapper.MapToContract(salesInvoice); result.State.Should().BeEquivalentTo(output); }
public void MapToApi_StateEnumNotExist_ThrowsException() { var current = new SalesInvoiceGet(); var salesInvoice = new Contract.Model.SalesInvoice() { State = (Contract.Model.SalesInvoiceStatus) 1234 }; Action a = () => _mapper.MapToApi(salesInvoice, current); a.Should().Throw <Exception>(); }
public void MapToApi_MapStateEnum_Correctly(Contract.Model.SalesInvoiceStatus input, string output) { var current = new SalesInvoiceGet(); var salesInvoice = new Contract.Model.SalesInvoice() { State = input }; var result = _mapper.MapToApi(salesInvoice, current); result.state.Should().BeEquivalentTo(output); }
public void GetById_CallsGetById_ReturnsMappedObjects() { var id = 1234; var salesInvoice = new SalesInvoiceGet(); _defaultConnector.Setup(c => c.GetById(id)).Returns(salesInvoice); var mappedItem = new Contract.Model.SalesInvoice(); _mapper.Setup(c => c.MapToContract(salesInvoice)).Returns(mappedItem); var item = _invoiceService.GetById(id); item.Should().BeEquivalentTo(mappedItem); }
public void Get_CallsGetList_ReturnsMappedObjects() { var salesInvoice = new SalesInvoiceGet(); _defaultConnector.Setup(c => c.GetList()).Returns(new List <SalesInvoiceGet>() { salesInvoice }); var mappedItem = new Contract.Model.SalesInvoice(); _mapper.Setup(c => c.MapToContract(salesInvoice)).Returns(mappedItem); var items = _invoiceService.Get(); items.Should().Contain(mappedItem); }
public void MapToContract_MapObject_Correctly() { var current = new SalesInvoiceGet(); var salesInvoice = new SalesInvoiceGet() { state = "draft", contact_id = 123, document_style_id = 12345, workflow_id = 12346, invoice_id = "AbC", due_date = "2016-10-20", invoice_date = "2016-11-20", id = 1, prices_are_incl_tax = true, total_price_excl_tax = 132, total_price_incl_tax = 190, total_tax = 58 }; var result = _mapper.MapToContract(salesInvoice); var expectedResult = new Contract.Model.SalesInvoice() { State = Contract.Model.SalesInvoiceStatus.Draft, Id = salesInvoice.id, DocumentStyleId = salesInvoice.document_style_id, WorkflowId = salesInvoice.workflow_id, InvoiceId = salesInvoice.invoice_id, PriceAreIncludedTax = salesInvoice.prices_are_incl_tax, DueDate = new DateTime(2016, 10, 20), InvoiceDate = new DateTime(2016, 11, 20), ContactId = salesInvoice.contact_id, TotalPriceExcludingTax = salesInvoice.total_price_excl_tax, TotalPriceIncludingTax = salesInvoice.total_price_incl_tax, TotalTax = salesInvoice.total_tax, }; result.Should().BeEquivalentTo(expectedResult, opt => opt .Excluding(p => p.Details) .Excluding(p => p.CustomFields)); }
public void MapToApi_MapObject_Correctly() { var current = new SalesInvoiceGet(); var salesInvoice = new Contract.Model.SalesInvoice() { State = Contract.Model.SalesInvoiceStatus.Draft, Id = 1, DocumentStyleId = 12345, WorkflowId = 12346, InvoiceId = "ABC", PriceAreIncludedTax = true, DueDate = new DateTime(2016, 10, 20), InvoiceDate = new DateTime(2016, 11, 20), ContactId = 123, TotalPriceExcludingTax = 123, TotalPriceIncludingTax = 150, TotalTax = 27, }; var result = _mapper.MapToApi(salesInvoice, current); var expectedResult = new SalesInvoicePost() { state = "draft", contact_id = salesInvoice.ContactId, document_style_id = salesInvoice.DocumentStyleId, workflow_id = salesInvoice.WorkflowId, invoice_id = salesInvoice.InvoiceId, due_date = "2016-10-20", invoice_date = "2016-11-20", id = salesInvoice.Id, prices_are_incl_tax = salesInvoice.PriceAreIncludedTax, total_price_excl_tax = salesInvoice.TotalPriceExcludingTax, total_price_incl_tax = salesInvoice.TotalPriceIncludingTax, total_tax = salesInvoice.TotalTax }; result.Should().BeEquivalentTo(expectedResult, opt => opt .Excluding(p => p.details_attributes) .Excluding(p => p.custom_fields_attributes)); }
public void Create_MapsToApi_CallsConnectorWithWrapper() { var salesInvoice = new Contract.Model.SalesInvoice(); var update = new SalesInvoicePost(); var resultContact = new SalesInvoiceGet() { id = 1234 }; _mapper.Setup(c => c.MapToApi(salesInvoice, null)).Returns(update); _defaultConnector.Setup(c => c.Create(It.Is <SalesInvoiceWrapper>(v => v.sales_invoice == update))).Returns(resultContact); _mapper.Setup(c => c.MapToContract(resultContact)).Returns(new Contract.Model.SalesInvoice() { Id = resultContact.id }); var result = _invoiceService.Create(salesInvoice); result.Id.Should().Be(resultContact.id); _defaultConnector.Verify(c => c.Create(It.Is <SalesInvoiceWrapper>(v => v.sales_invoice == update)), Times.Once); }