Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verification of Enum fails #59

Closed
jezzsantos opened this issue May 8, 2017 · 3 comments
Closed

Verification of Enum fails #59

jezzsantos opened this issue May 8, 2017 · 3 comments

Comments

@jezzsantos
Copy link

jezzsantos commented May 8, 2017

Consider this arrangement:

    enum AnEnum{
        One = 1,
        Two,
        Three
    }

    class AClass {
        property1: string;
        property2: number;
        property3: AnEnum

        amethod(){}
    }

    class CUT{

        do(instance:AClass){

        }
    }

Now we write two tests:

    it('matches without enum', () => {
        const mock = TypeMoq.Mock.ofType(CUT, TypeMoq.MockBehavior.Strict);

        mock.setup(f => f.do(TypeMoq.It.isObjectWith({property1: 'one', property2: 1} as AClass)))
            .verifiable();
        mock.setup(f => f.do(TypeMoq.It.isObjectWith({property1: 'two', property2: 2} as AClass)))
            .verifiable();

        const call1 = new AClass();
        call1.property1 = 'one';
        call1.property2 = 1;
        call1.property3 = AnEnum.One;

        const call2 = new AClass();
        call2.property1 = 'two';
        call2.property2 = 2;
        call1.property3 = AnEnum.Two;

        mock.object.do(call1);
        mock.object.do(call2);

        mock.verifyAll();
    });

    it('does not match with enum', () => {
        const mock = TypeMoq.Mock.ofType(CUT, TypeMoq.MockBehavior.Strict);

        mock.setup(f => f.do(TypeMoq.It.isObjectWith({property1: 'one', property2: 1, property3: AnEnum.One} as AClass)))
            .verifiable();
        mock.setup(f => f.do(TypeMoq.It.isObjectWith({property1: 'two', property2: 2, property3: AnEnum.Two} as AClass)))
            .verifiable();

        const call1 = new AClass();
        call1.property1 = 'one';
        call1.property2 = 1;
        call1.property3 = AnEnum.One;

        const call2 = new AClass();
        call2.property1 = 'two';
        call2.property2 = 2;
        call1.property3 = AnEnum.Two;

        mock.object.do(call1);
        mock.object.do(call2);

        mock.verifyAll(); //THIS FAILS!!
    });

The later test fails. The only difference is the verification of the call that includes an enum value.

Any workaround?

@jezzsantos
Copy link
Author

jezzsantos commented May 8, 2017

Strangely enough, when you inline the call, the test passes:

    it('matches with inlined enum', () => {
        const mock = TypeMoq.Mock.ofType(CUT, TypeMoq.MockBehavior.Strict);

        mock.setup(f => f.do(TypeMoq.It.isObjectWith({property1: 'one', property2: 1, property3: AnEnum.One} as AClass)))
            .verifiable();
        mock.setup(f => f.do(TypeMoq.It.isObjectWith({property1: 'two', property2: 2, property3: AnEnum.Two} as AClass)))
            .verifiable();

        mock.object.do({property1: 'one', property2: 1, property3: AnEnum.One} as AClass);
        mock.object.do({property1: 'two', property2: 2, property3: AnEnum.Two} as AClass);

        mock.verifyAll();
    });

So not sure what is going on in here, but looks like a bug comparing the enum values somehow?

@florinn
Copy link
Owner

florinn commented May 8, 2017

It seems there is a typo in your tests. Instead of

const call2 = new AClass();
call2.property1 = 'two';
call2.property2 = 2;
call1.property3 = AnEnum.Two;

I guess you wanted to write

const call2 = new AClass();
call2.property1 = 'two';
call2.property2 = 2;
call2.property3 = AnEnum.Two;

@jezzsantos
Copy link
Author

Oh boy! stoopid me. Thanks for pointing that typo out.

I guess this isn't a good repro test of what I am seeing. I'm pulling my hair out.
Let me investigate further, I'll close this for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants