Frage

I have an enum in my business object defined.

This enum is although defined in the data transfer object.

The dto enum is not of the type of the business object because they should not know of each other.

When I get now this dto from the client and map the dto to a business object and insert the data in the database I want to assert that passed dto.enum has the same value as the inserted enum value in the database.

Thats my error message I get:

Expected: A

  But was:  A

Actually they have the same value but different type: dto.enum vs businessobject.enum.

So where would you define this enum then that both objects can it and both objects does not have a coupling to each other?

I thought about putting an extra c# class in my business layer and inside the enum definition used by the dto AND business object so the assertion would work.

What would you do?

War es hilfreich?

Lösung

You should put the enum in an external util class that both objects would have access to by project reference (Model Layer most likely). Then they can use the same enum and you won't have to attempt to cast, convert or couple (assuming the enums are exact duplicates of eachother).

Andere Tipps

If the names are exactly the same you could simply do the following:

BusinessEnumType businessEnum = GetBusinessEnum();
DTOEnumType dtoEnum = GetDTOEnum();

Assert.AreEqual(businessEnum.ToString(), dtoEnum.ToString());

Not ideal perhaps, but will save you having to defining things all over the place.

You might also be able to write an IEqualityComparer that you could use to check if something of BusinessEnumType is the "same" as DTOEnumType, but that can be a maintenance headache.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top