예제 #1
0
        public void Update_GetAndUpdate_CallsConnectorWithUpdate()
        {
            var salesInvoiceId = 1234;
            var existing       = new RecurringSalesInvoiceGet()
            {
                id = salesInvoiceId,
            };
            var data = new Contract.Model.RecurringSalesInvoice()
            {
                Id = existing.id
            };
            var existingMapped = new RecurringSalesInvoicePost();
            var saveResult     = new RecurringSalesInvoiceGet();
            var mappedResult   = new Contract.Model.RecurringSalesInvoice()
            {
                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 <RecurringSalesInvoiceWrapper>(v => v.recurring_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 <RecurringSalesInvoiceWrapper>(v => v.recurring_sales_invoice == existingMapped)), Times.Once);
        }
예제 #2
0
        public void MapToContract_MapDetails_CallsMapper()
        {
            var salesInvoiceDetail1 = new SalesInvoiceDetail()
            {
            };
            var salesInvoiceDetail2 = new SalesInvoiceDetail()
            {
            };
            var salesInvoice = new RecurringSalesInvoiceGet()
            {
                frequency_type = "day",
                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();
        }
예제 #3
0
        public void MapToContract_MapCustomFields_CallsMapper()
        {
            var customField1 = new CustomField()
            {
                id = 123456, value = "test1"
            };
            var customField2 = new CustomField()
            {
                id = 123457, value = "test2"
            };
            var salesInvoice = new RecurringSalesInvoiceGet()
            {
                frequency_type = "day",
                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();
        }
예제 #4
0
        public void MapToApi_MapSalesInvoiceDetails_CallsMapper()
        {
            var current             = new RecurringSalesInvoiceGet();
            var salesInvoiceDetail1 = new Contract.Model.SalesInvoiceDetail()
            {
            };
            var salesInvoiceDetail2 = new Contract.Model.SalesInvoiceDetail()
            {
            };
            var salesInvoice = new Contract.Model.RecurringSalesInvoice()
            {
                FrequencyType = FrequencyType.Day,
                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();
        }
예제 #5
0
        public void MapToApi_MapCustomFields_CallsMapper()
        {
            var current      = new RecurringSalesInvoiceGet();
            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.RecurringSalesInvoice()
            {
                FrequencyType = FrequencyType.Day,
                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();
        }
예제 #6
0
        public void GetById_CallsGetById_ReturnsMappedObjects()
        {
            var id           = 1234;
            var salesInvoice = new RecurringSalesInvoiceGet();

            _defaultConnector.Setup(c => c.GetById(id)).Returns(salesInvoice);

            var mappedItem = new Contract.Model.RecurringSalesInvoice();

            _mapper.Setup(c => c.MapToContract(salesInvoice)).Returns(mappedItem);

            var item = _invoiceService.GetById(id);

            item.Should().BeEquivalentTo(mappedItem);
        }
예제 #7
0
        public void Get_CallsGetList_ReturnsMappedObjects()
        {
            var salesInvoice = new RecurringSalesInvoiceGet();

            _defaultConnector.Setup(c => c.GetList()).Returns(new List <RecurringSalesInvoiceGet>()
            {
                salesInvoice
            });

            var mappedItem = new Contract.Model.RecurringSalesInvoice();

            _mapper.Setup(c => c.MapToContract(salesInvoice)).Returns(mappedItem);

            var items = _invoiceService.Get();

            items.Should().Contain(mappedItem);
        }
예제 #8
0
        public void MapToApi_MapObject_Correctly()
        {
            var current      = new RecurringSalesInvoiceGet();
            var salesInvoice = new Contract.Model.RecurringSalesInvoice()
            {
                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,
                FrequencyType          = FrequencyType.Day,
                Frequency              = 1,
            };

            var result = _mapper.MapToApi(salesInvoice, current);

            var expectedResult = new RecurringSalesInvoicePost()
            {
                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,
                frequency_type       = "day",
                frequency            = salesInvoice.Frequency
            };

            result.Should().BeEquivalentTo(expectedResult,
                                           opt => opt
                                           .Excluding(p => p.details_attributes)
                                           .Excluding(p => p.custom_fields_attributes));
        }
예제 #9
0
        public void MapToContract_MapObject_Correctly()
        {
            var current = new RecurringSalesInvoiceGet();

            var salesInvoice = new RecurringSalesInvoiceGet()
            {
                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,
                frequency_type       = "day",
            };

            var result = _mapper.MapToContract(salesInvoice);

            var expectedResult = new Contract.Model.RecurringSalesInvoice()
            {
                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,
                FrequencyType          = FrequencyType.Day
            };

            result.Should().BeEquivalentTo(expectedResult,
                                           opt => opt
                                           .Excluding(p => p.Details)
                                           .Excluding(p => p.CustomFields));
        }
예제 #10
0
        public void Create_MapsToApi_CallsConnectorWithWrapper()
        {
            var salesInvoice  = new Contract.Model.RecurringSalesInvoice();
            var update        = new RecurringSalesInvoicePost();
            var resultContact = new RecurringSalesInvoiceGet()
            {
                id = 1234
            };

            _mapper.Setup(c => c.MapToApi(salesInvoice, null)).Returns(update);
            _defaultConnector.Setup(c => c.Create(It.Is <RecurringSalesInvoiceWrapper>(v => v.recurring_sales_invoice == update))).Returns(resultContact);
            _mapper.Setup(c => c.MapToContract(resultContact)).Returns(new Contract.Model.RecurringSalesInvoice()
            {
                Id = resultContact.id
            });

            var result = _invoiceService.Create(salesInvoice);

            result.Id.Should().Be(resultContact.id);
            _defaultConnector.Verify(c => c.Create(It.Is <RecurringSalesInvoiceWrapper>(v => v.recurring_sales_invoice == update)), Times.Once);
        }