How is the Unit Test function that inserts a record into the RIA services database?

This is an example function that works with an entity, stores it in db, and then causes problems because we cannot write Unit Test for it. Check this:

// this class exists in a Silverlight Class Library
public class EmployeeSaver
{
    ....

    public void Go()
    {
        Employee e = new Employee();

        e.Name="Jeremiah";

        ... // Other stuff that really needs to be tested

        _DataContext.Employees.Add(e);
        _DataContext.SubmitChanges();

    }
}

Because of the nature of RIA services, DomainService does not start inside the Silverlight Unit Testing platform. This means that I do not have access to the RIA when I perform my unit tests.

We were thinking about mock databases, but this class actually creates an Entity (Employee) to add to the database. This is problematic because Mock Databases do not use this object, but the MockEntity class, which is similar to the original object.

We are not trying to test the RIA itself, but how do we use entities created by the RIA.

My ultimate goal would be to write a function like this:

[TestMethod]
public void Test()
{
    EmployeeSaver s = new EmployeeSaver();
    s.Go();

    Assert.IsEqual( DataContext.Employees.Last().Name, "Jeremiah" );
}

? ? Silverlight Testing Framework?

+3
2

unit test _DataContext. Go, :       _DataContext.Employees.Add();       _DataContext.SubmitChanges(); . .

Go , , , SubmitChanges.

: , , Go _DataContext. , _DataContext, unit test Go , Go _DataContext. , Go . , _DataContext, , unit test . " TDD".

+2

. ​​, .

. _DataContext - RhinoMocks, , , ( , _DataContext.SubmitChanges() ( unit test) , Go save.

+1

Source: https://habr.com/ru/post/1720012/


All Articles