microsoft / UnitTestBoilerplateGenerator

An extension for Visual Studio that generates a unit test boilerplate from a given class, setting up mocks for all dependencies. Supports NUnit, Visual Studio Test, Moq and SimpleStubs.
MIT License
158 stars 51 forks source link

DateTime object in Class Constructor Argument List Generated and Invalid Test Format #10

Closed JimKay1941 closed 7 years ago

JimKay1941 commented 7 years ago

Installed product versions

Description

I have a class, Student with a constructor having a DateTime object in the argument list.

The extension created these statements: private Mock mockDateTime; mockDateTime = mockRepository.Create();

Steps to recreate

  1. Create a simple Class with DateTime as an object in the argument list.
  2. Create a test for the Class
  3. The above error(s) will appear. "the type 'DateTime' must be a reference type in order to use it as a parameter 'T' in the generic type or method 'mockfactory.create()'" "the type "System.DateTime" must be a reference type in order to use it as parameter 'T'"

    Current behavior

    The generated statements cannot be copiled.

Expected behavior

Put DateTime directly in the argument list and do not attempt to use moq.

JimKay1941 commented 7 years ago

It seem your system is editing out > and < so I will have to resubmit them. private Mock<DateTime> mockDateTime; this.mockDateTime = this.mockRepository.Create<DateTime>();

RandomEngy commented 7 years ago

Thanks for the report. Some types are not mockable, in this case DateTime. You'll need to create and inject it yourself. If I made a change here it would be to detect that DateTime is a non-mockable struct and insert "TODO" instead.

JimKay1941 commented 7 years ago

Indeed, I have already done the inject myself.

I was only suggesting you make the change to detect DateTime as non-mockable.

Thanks again for the reply and for your extension! It really helps me.

RandomEngy commented 7 years ago

Fixed in 1.5.10. We no longer try to make mock objects out of non-reference types.

JimKay1941 commented 7 years ago

¡Muchas Gracias!