Developer forum

Forum » Development » Create a Dummy order for Unit tests

Create a Dummy order for Unit tests

Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi,

 

We're trying to create just a dummy order for Unit test purposes on our customizations. I know that currently this relies a lot on context, so I wonder if there's an easier way OR if we're down a bunny trail or it simply can't get done.

 

This what we have so far

using Dynamicweb.Ecommerce.International;
using Dynamicweb.Ecommerce.Orders;
using Dynamicweb.Ecommerce.Prices;
using Dynamicweb.Ecommerce.Products;

namespace Dna.Lorann.Tests
{
    public class Orders
    {
        public static Order GetOrderWithOneProductWithWeight40()
        {
            var order = new Order(GetDummyCurrency(), GetDummyCountry(),GetDummyLanguage());

            return order;
        }

        private static Currency GetDummyCurrency()
        {
            return new Currency();
        }

        private static Country GetDummyCountry()
        {
            return new Country();
        }

        private static Language GetDummyLanguage()
        {
            return new Language();
        }
    }
}

And this is the error we get this error

System.NullReferenceException : Object reference not set to an instance of an object.
   at Dynamicweb.Core.SystemInformation.GetBasePath(String& relativePath)
   at Dynamicweb.Core.SystemInformation.MapPath(String relativePath)
   at Dynamicweb.Configuration.SystemConfiguration.get_Instance()
   at Dynamicweb.Ecommerce.Orders.Order.set_VatCountry(Country value)
   at Dynamicweb.Ecommerce.Orders.Order..ctor(Currency currency, Country country, Language language)
   at Dna.Lorann.Tests.Orders.GetOrderWithOneProductWithWeight40() in C:\Users\Pedro Meias\Desktop\Dna.Lorann.Tests\Orders.cs:line 13
   at Dna.Lorann.Tests.Packages.OneOrderWithOneProductUnder40Lbs() in C:\Users\Pedro Meias\Desktop\Dna.Lorann.Tests\Packages.cs:line 14
 
Best Regards,
Nuno Aguiar

Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

In the source of Dynamicweb 9 solution, there is a test folder with a number of test projects.

In there you can see how to mock various things - that is the best way to go. It is possible, though not easy since there is database, file system, users and a lot of stuff that does not exist in your unit environment

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi Nicolai,

 

Yeah thanks. I was hoping it would be simpler indeed. For the immediate need we were able to abstract the dependency (our custom code no longer depends on a list of Orderlines, but a processed list of new objects).

 

I'll look into this further when I have some more time, as we'd anticipate a few needs on this, and having the ability to generate some orders with some data and some orderlines to mock the behavior of Providers (Shipping, Payment, Address, Tax or otherwise) will be important for us to save time, reduce bugs and improve code quality.

 

Thanks again,

Nuno Aguiar

 

You must be logged in to post in the forum