public void TestCreateDiscoveryConstant()
        {
            var decorator = new EasyConstructServiceDecorator();
            CodeMemberField field = decorator.CreateDiscoveryConstant(CreateBuzzService());

            // Validate the constant.
            Assert.AreEqual(EasyConstructServiceDecorator.DiscoveryConstantName, field.Name);
            Assert.AreEqual(typeof(string).ToString(), field.Type.BaseType);
            Assert.IsInstanceOf<CodePrimitiveExpression>(field.InitExpression);
        }
        public void TestCreateEmptyConstructor()
        {
            var decorator = new EasyConstructServiceDecorator();
            CodeConstructor constructor = decorator.CreateEmptyConstructor();

            // Check parameters.
            Assert.AreEqual(0, constructor.Parameters.Count);

            // Check statements.
            Assert.AreEqual(0, constructor.Statements.Count);

            // Check chained parameters.
            Assert.AreEqual(1, constructor.ChainedConstructorArgs.Count);
            Assert.IsInstanceOf<CodeFieldReferenceExpression>(constructor.ChainedConstructorArgs[0]);
        }
        public void TestCreateAuthenticatorConstructor()
        {
            var codeType = new CodeTypeDeclaration("TestClass");
            var decorator = new EasyConstructServiceDecorator();
            var service = CreateBuzzService();
            CodeConstructor constructor = decorator.CreateAuthenticatorConstructor(service, codeType);

            // Check parameters.
            Assert.AreEqual(1, constructor.Parameters.Count);
            Assert.AreEqual(typeof(IAuthenticator).FullName, constructor.Parameters[0].Type.BaseType);
            Assert.AreEqual(ServiceClassGenerator.AuthenticatorName, constructor.Parameters[0].Name);

            // Check statements.
            Assert.AreEqual(0, constructor.Statements.Count);

            // Check chained parameters.
            Assert.AreEqual(2, constructor.ChainedConstructorArgs.Count);
        }
        public void TestDecorateClass()
        {
            var codeType = new CodeTypeDeclaration("TestClass");
            var decorator = new EasyConstructServiceDecorator();
            var service = CreateBuzzService();

            decorator.DecorateClass(service, codeType);

            Assert.AreEqual(3, codeType.Members.Count); // We expect two members to be added.

            // Test the empty constructor.
            Assert.IsInstanceOf(typeof(CodeConstructor), codeType.Members[0]);
            var constructor = (CodeConstructor)codeType.Members[0];
            Assert.AreEqual(0, constructor.Parameters.Count);
            Assert.AreEqual(0, constructor.Statements.Count);

            // Test the constructor taking the authenticator.
            Assert.IsInstanceOf(typeof(CodeConstructor), codeType.Members[1]);
            var constructor2 = (CodeConstructor)codeType.Members[1];
            Assert.AreEqual(1, constructor2.Parameters.Count);
            Assert.AreEqual(0, constructor2.Statements.Count);

            // Test the generated constant.
            Assert.IsInstanceOf(typeof(CodeMemberField), codeType.Members[2]);
            Assert.AreEqual(EasyConstructServiceDecorator.DiscoveryConstantName, codeType.Members[2].Name);
        }