CommonTypes.cs :  » Inversion-of-Control-Dependency-Injection » Spring.net » Spring » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Inversion of Control Dependency Injection » Spring.net 
Spring.net » Spring » CommonTypes.cs
#region License

/*
 * Copyright 2002-2004 the original author or authors.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#endregion

using System;
using System.Collections;
using System.ComponentModel;
using DotNetMock;
using Spring.Objects.Factory;
using Spring.Objects.Factory.Config;

namespace Spring{
  public class MockConfigurableObjectFactory : MockObject, IConfigurableObjectFactory
  {
    private ExpectationCounter _destroyCalls = new ExpectationCounter("MockConfigurableObjectFactory.DestroySingletonCalls");

    public void SetDisposeCalls(int expectedCalls)
    {
      _destroyCalls.Expected = expectedCalls;
    }

    #region IConfigurableObjectFactory Members

    public void RegisterSingleton(string objectName, object singletonObject)
    {
    }

      public object GetSingleton(string objectName)
      {
          throw new NotImplementedException();
      }

      public void Dispose()
    {
      _destroyCalls.Inc();
    }

    public void IgnoreDependencyType(Type type)
    {
    }


      public bool IsCurrentlyInCreation(string objectName)
      {
          throw new NotImplementedException();
      }

      public void AddObjectPostProcessor(IObjectPostProcessor objectPostProcessor)
    {
    }

    public int ObjectPostProcessorCount
    {
      get { throw new NotImplementedException(); }
    }

    public void RegisterAlias(string objectName, string alias)
    {
    }

    public void RegisterCustomConverter(Type requiredType, TypeConverter converter)
    {
    }

    public bool ContainsSingleton(string name)
    {
      throw new NotImplementedException();
    }

      public string[] SingletonNames
      {
          get { throw new NotImplementedException(); }
      }

      #region ISingletonObjectRegistry Members

      public int SingletonCount
      {
          get { throw new NotImplementedException(); }
      }

      #endregion

      public IObjectDefinition GetObjectDefinition(string objectName)
    {
      return null;
    }

    public IObjectFactory ParentObjectFactory
    {
      set
      {
      }
    }

    #endregion

    #region IHierarchicalObjectFactory Members

    IObjectFactory IHierarchicalObjectFactory.ParentObjectFactory
    {
      get { return null; }
    }

      public bool ContainsLocalObject(string name)
      {
          throw new NotImplementedException();
      }

      #endregion

    #region IObjectFactory Members

      public bool IsCaseSensitive
      {
          get { return true; }
      }

      public object this[string name]
    {
      get { return null; }
    }

    public bool ContainsObject(string name)
    {
      return false;
    }

      public object CreateObject(string name, Type requiredType, object[] arguments)
      {
            return null;
      }

    public string[] GetAliases(string name)
    {
      return null;
    }

    public object GetObject(string name, Type requiredType)
    {
      return null;
    }

    object IObjectFactory.GetObject(string name)
    {
      return null;
    }

      public object GetObject(string name, object[] arguments)
      {
          return null;
      }

      public object GetObject(string name, Type requiredType, object[] arguments)
      {
          return null;
      }

      public bool IsSingleton(string name)
    {
      return false;
    }


      public bool IsPrototype(string name)
      {
          return false;
      }

      public Type GetType(string name)
    {
      return null;
    }



      public bool IsTypeMatch(string name, Type targetType)
      {
          return false;
      }

      public object ConfigureObject(object target)
    {
        return null;
    }

        public object ConfigureObject(object target, string name)
    {
            return null;
        }

    #endregion
  }

  public class MockObjectFactory : MockObject, IObjectFactory
  {
    private Exception _exceptionToThrow = null;

    public Exception ExceptionToThrow
    {
      get { return _exceptionToThrow; }
      set { _exceptionToThrow = value; }
    }

    #region IObjectFactory Members

      public bool IsCaseSensitive
      {
          get { innerExecute();
              return true; }
      }

      public object this[string name]
    {
      get
      {
        innerExecute();
        return null;
      }
    }

    public bool ContainsObject(string name)
    {
      innerExecute();
      return false;
    }

    public string[] GetAliases(string name)
    {
      innerExecute();
      return null;
    }

    public object CreateObject(string name, Type requiredType, object[] arguments)
      {
            innerExecute();
            return null;
      }

        public object GetObject(string name, Type requiredType)
    {
      innerExecute();
      return null;
    }

    object IObjectFactory.GetObject(string name)
    {
      innerExecute();
      return null;
    }

      public object GetObject(string name, object[] arguments)
      {
            innerExecute();
            return null;
      }

      public object GetObject(string name, Type requiredType, object[] arguments)
      {
            innerExecute();
            return null;
      }

      public bool IsSingleton(string name)
    {
      innerExecute();
      return false;
    }


      public bool IsPrototype(string name)
      {
            innerExecute();
          return false;
      }

      public Type GetType(string name)
    {
      innerExecute();
      return null;
    }


      public bool IsTypeMatch(string name, Type targetType)
      {
          innerExecute();
          return false;
      }

      public object ConfigureObject(object target)
    {
            return null;
        }

        public object ConfigureObject(object target, string name)
    {
            return null;
        }

    #endregion

    private void innerExecute()
    {
      if (_exceptionToThrow != null)
      {
        throw _exceptionToThrow;
      }
    }

    public void Dispose()
    {
    }
  }

    public class Inventor
    {
        public string Name;
        public string Nationality;
        public string[] Inventions;
#if NET_2_0
        public DateTime? DateOfGraduation;
#endif
        private DateTime dob;
        private Place pob;

        public Inventor() : this(null, DateTime.MinValue, null)
        {}

        public Inventor(string name, DateTime dateOfBirth, string nationality)
        {
            this.Name = name;
            this.dob = dateOfBirth;
            this.Nationality = nationality;
            this.pob = new Place();
        }

        public DateTime DOB
        {
            get { return dob; }
            set { dob = value; }
        }

        /// <summary>
        /// R/W PlaceOfBirth property
        /// </summary>
        public Place POB
        {
            get { return pob; }
            set { pob = value; }
        }

        /// <summary>
        /// Readonly
        /// </summary>
        public Place PlaceOfBirth
        {
            get { return pob; }
        }

        public int GetAge(DateTime on)
        {
            // not very accurate, but it will do the job ;-)
            return on.Year - dob.Year;
        }
    }

    public class Place
    {
        public string City;
        public string Country;
    }

    public class Society
    {
        public string Name = "League of Extraordinary Gentlemen";
        public static string Advisors = "advisors";
        public static string President = "president";

        private IList members = new ArrayList();
        private IDictionary officers = new Hashtable();

        public IList Members
        {
            get { return members; }
        }

        public IDictionary Officers
        {
            get { return officers; }
        }

        public bool IsMember(string name)
        {
            bool found = false;
            foreach (Inventor inventor in members)
            {
                if (inventor.Name == name)
                {
                    found = true;
                    break;
                }
            }
            return found;
        }
    }


}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.