1

everyone, I'm writing a unit test for my Builder class and I have the following error. Method TestDB.BuilderTest.CustomerBuilderTest.CLassInitialize has the wrong signature. The method must be static, public does not return a value and should take a single parameter of type TestContext. Additionally, if you are using async-await in the method then return-type must be Task.

this is My unit test

    [TestClass]
   public class CustomerBuilderTest
    {
        private static CustomerDeserializer _customerDeserializer;

        private static string path;

        [ClassInitialize]
        public static void CLassInitialize(TestContext context)
        {
            path = Path.Combine(Environment.CurrentDirectory, @"Folder\", "Customer.json");
        }

        [TestInitialize]
        public static void TestInitialize()
        {
            _customerDeserializer = new CustomerDeserializer();

        }

        [TestMethod]
        public void CusomerBuilder_MustReturnCustomers()
        {
            //Arange


            //Act
            var dtos = CustomerDeserializer.Deserialize(path);
            var dto = dtos.FirstOrDefault(e => e.Email == "hi@gmail.com");
            var customer = CustomerBuilder.CustomerBuild(dto);

            //Asset

            Assert.IsNotNull(dto);
            Assert.AreEqual(customer.FirstName,"tina");


        }

    }
}

this is My Builder class

 public class CustomerBuilder
    {
        public static Customer CustomerBuild(DtoCustomer dto)
        {
            return new Customer()
            {
                FirstName = dto.FirstName,
                LastName = dto.LastName,
                Address = dto.Address,
                Email = dto.Email,
                Code = int.Parse(dto.Code),
                PhoneNumber = dto.Phone

            };
        }
    }

I checked lots of sites but I didn't find any solution can you help me?

Nazanin
  • 217
  • 1
  • 6
  • 14

1 Answers1

1

The ClassInitialize attribute need to have paranthesis added and secondly try to have the method name different than attribute as it's probably confusing the compiler. So try like:

[ClassInitialize()]
public void CLassInitialization(TestContext context)
{
    path = Path.Combine(Environment.CurrentDirectory, @"Folder\", "Customer.json");
}

and you might need to apply same for the TestInitialize as well :

[TestInitialize]
public void TestInitialization()
{
    _customerDeserializer = new CustomerDeserializer();
}
Ehsan Sajjad
  • 61,834
  • 16
  • 105
  • 160