public void SetUp()
        {
            Mock <IEanEicCheckerHttpClient> mockClient = new Mock <IEanEicCheckerHttpClient>();

            //for "invalid" ean code returns invalid, ean ok otherwise
            mockClient.Setup(c => c.Post(It.IsAny <EanEicCode>()))
            .Returns(
                (EanEicCode code) =>
                code.Code == "invalid"
                              ? new CheckResult(CheckResultCode.EanInvalidCheckCharacter)
                              : new CheckResult(CheckResultCode.EanOk));

            EanEicCheckerHttpClient = mockClient.Object;

            OpmRepository = new OpmInMemoryRepository();
            OpmRepoFiller.Fill(OpmRepository, PositiveTestData);
            IUserAccessService userAccessService = new UserAccessService(new UserAccessInMemoryRepository(),
                                                                         new TimeSpan(0, 1, 0), 999);

            IIdentityManagement identityManagement = new IdentityManagementMock();
            IOpmVerificator     opmVerificator     = new OpmVerificator(identityManagement, mockClient.Object, OpmRepository,
                                                                        userAccessService);

            Controller = new OpmDuplicityController(opmVerificator, userAccessService)
            {
                Request       = new HttpRequestMessage(),
                Configuration = new HttpConfiguration()
            };
        }
Ejemplo n.º 2
0
        public static void Register(HttpConfiguration config)
        {
            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );

            // Uncomment the following line of code to enable query support for actions with an IQueryable or IQueryable<T> return type.
            // To avoid processing unexpected or malicious queries, use the validation settings on QueryableAttribute to validate incoming queries.
            // For more information, visit http://go.microsoft.com/fwlink/?LinkId=279712.
            //config.EnableQuerySupport();

            // To disable tracing in your application, please comment out or remove the following line of code
            // For more information, refer to: http://www.asp.net/web-api
            config.EnableSystemDiagnosticsTracing();

            #region IoC
            var container = new UnityContainer();
            container.RegisterType <IOpmVerificator, OpmVerificator>(new HierarchicalLifetimeManager());


            string idmUrl           = System.Configuration.ConfigurationManager.AppSettings["IdmUrl"];
            IIdentityManagement idm = new IdentityManagement(idmUrl);
            container.RegisterInstance(idm);

            string eanEicCheckerUrl = System.Configuration.ConfigurationManager.AppSettings["EanEicCheckerUrl"];
            IEanEicCheckerHttpClient eanEicCheckerHttpClient = new EanEicCheckerHttpClient(eanEicCheckerUrl);
            container.RegisterInstance(eanEicCheckerHttpClient);


            IOpmRepository opmInMemoryRepository = new OpmInMemoryRepository();
            OpmRepoFiller.Fill(opmInMemoryRepository);
            container.RegisterInstance(opmInMemoryRepository);

            config.DependencyResolver = new UnityResolver(container);
            #endregion IoC
        }