Inheritance: IService2
Ejemplo n.º 1
0
        public void Add_WeaveTest1()
        {
            Service1 s1 = new Service1();
            Service2 s2 = new Service2();

            ew.Add(s1);
            ew.Add(s2);

            s1.Trigger();
            Assert.AreEqual(1, s2.EventCount);
        }
Ejemplo n.º 2
0
            public RootClass(Service1 service1, Service2 service2, string stringProperty, int intProperty)
            {
                if (service1 == null)
                    throw new ArgumentNullException("service1");

                if (service2 == null)
                    throw new ArgumentNullException("service2");

                this.service1 = service1;
                this.service2 = service2;
                StringProperty = stringProperty;
                IntProperty = intProperty;
            }
Ejemplo n.º 3
0
 public RootClass(Service1 service1, Service2 service2)
     : this(service1, service2, "DEFAULT", 1976)
 {
 }
Ejemplo n.º 4
0
 public void SetUp()
 {
     impl1 = new Service();
     impl2 = new Service2();
     proxy1 = Helper.GetProxy<IService>(impl1);
 }
Ejemplo n.º 5
0
        public void ServiceManager_Test02() {
            PropertyOwner propertyOwner = new PropertyOwner();
            int servicesAdded = 0;
            int servicesRemoved = 0;

            Service1 s1 = new Service1();
            Service2 s2 = new Service2();

            ServiceManager.AddService<IService1>(s1, propertyOwner, null);

            ServiceManager.GetService<IService1>(propertyOwner).Should().Be(s1);
            ServiceManager.GetService<Service1>(propertyOwner).Should().Be(s1);

            ServiceManager.RemoveService<IService1>(propertyOwner);
            ServiceManager.GetService<IService1>(propertyOwner).Should().BeNull();

            ServiceManager sm = ServiceManager.FromPropertyOwner(propertyOwner, null);
            sm.Should().NotBeNull();

            EventHandler<ServiceManagerEventArgs> onServiceAdded = (object sender, ServiceManagerEventArgs e) => {
                servicesAdded++;

                switch (servicesAdded) {
                    case 1:
                        e.Service.Should().Be(s1);
                        e.ServiceType.Should().Be(typeof(IService1));
                        break;
                    case 2:
                        e.Service.Should().Be(s2);
                        e.ServiceType.Should().Be(typeof(IService2));
                        break;
                }
            };

            EventHandler<ServiceManagerEventArgs> onServiceRemoved = (object sender, ServiceManagerEventArgs e) => {
                servicesRemoved++;

                switch (servicesRemoved) {
                    case 1:
                        e.ServiceType.Should().Be(typeof(IService1));
                        break;
                    case 2:
                        e.ServiceType.Should().Be(typeof(IService2));
                        break;
                }
            };

            sm.ServiceAdded += onServiceAdded;
            sm.ServiceRemoved += onServiceRemoved;

            ServiceManager.AddService<IService1>(s1, propertyOwner, null);
            ServiceManager.AddService<IService2>(s2, propertyOwner, null);

            ServiceManager.RemoveService<IService1>(propertyOwner);
            ServiceManager.RemoveService<IService2>(propertyOwner);

            ServiceManager.GetService<IService1>(propertyOwner).Should().BeNull();
            ServiceManager.GetService<IService2>(propertyOwner).Should().BeNull();
        }
Ejemplo n.º 6
0
        public void Add_WeaveTest2()
        {
            Service1 s1 = new Service1();
            Service2 s2 = new Service2();

            // Add in wrong order won't weave
            ew.Add(s2);
            ew.Add(s1);

            s1.Trigger();
            Assert.AreEqual(0, s2.EventCount);
        }
Ejemplo n.º 7
0
 public Usecase2(Service2 service2)
 {
     Service2 = service2;
 }
Ejemplo n.º 8
0
        private async void BookNewOrder()
        {
            try
            {
                var streetaddress       = txtAdress.Text;
                var postalcode          = txtPostalCode.Text;
                int convertedpostalcode = int.Parse(postalcode);
                var city = txtCity.Text;

                string[] subs = streetaddress.Split(' ');

                foreach (var sub in subs)
                {
                    Console.WriteLine($"Substring: {sub}");
                }


                string streetname   = subs[0];
                string streetNumber = subs[1];


                var additionalServiceCodeStandard = new List <string>
                {
                    "A1"
                };
                var itemList = new List <long>
                {
                    373500489530470000
                };



                List <PickupService> newist = new List <PickupService>();

                newist.Add(new PickupService()
                {
                    typeOfItem = "parcel", noUnits = 1
                });



                Service Servicebody = new Service
                {
                    basicServiceCode      = "19",
                    additionalServiceCode = new List <string>
                    {
                        "A1"
                    }
                };



                Service2 service2 = new Service2
                {
                    service = Servicebody
                };

                Shipment2 shipment2 = new Shipment2
                {
                    shipment = service2
                };

                var Shipmentbody = new Shipment
                {
                    items = itemList
                };
                var LocationBody = new Location
                {
                    place        = "Company name or information about pickup place e.g.garage",
                    streetName   = streetname,
                    streetNumber = streetNumber,
                    postalCode   = convertedpostalcode,
                    city         = city,
                    countryCode  = "SE"
                };

                Location2 location2 = new Location2
                {
                    location = LocationBody
                };

                var OrderBody = new Order
                {
                    customerNumber = "1234567891",
                    orderReference = "Ref-1212122A",
                    contactName    = "Nils Andersson",
                    contactEmail   = "*****@*****.**",
                    phoneNumber    = "+4670788888",
                    smsNumber      = "+4670788888",
                    entryCode      = "8216"
                };

                var Order2 = new Order2
                {
                    order = OrderBody
                };

                var PickUpBody = new PickupService
                {
                    typeOfItem = "parcel",
                    noUnits    = 1
                };

                var PickUp2 = new PickUp2
                {
                    pickups = newist
                };


                var datesandtimesBody = new DateAndTimes
                {
                    readyPickupDate    = new DateTime(2021, 5, 13),
                    latestPickupDate   = new DateTime(2021, 5, 13),
                    earliestPickupDate = new DateTime(2021, 5, 13)
                };

                var datesandtimes2 = new DateAndTimes2
                {
                    DateAndTimes = datesandtimesBody
                };



                var client = new RestClient("https://api2.postnord.com/rest/order/v1/pickup/SE?apikey=0ba91457361a67d1495aefa8519ba3cb");
                client.Timeout = -1;
                var request = new RestRequest(Method.POST);
                // request.AddParameter("text/plain", "{\r\n  \"shipment\": {\r\n    \"service\": {\r\n      \"basicServiceCode\": \"19\",\r\n      \"additionalServiceCode\": [\r\n        \"A1\"\r\n      ]\r\n    },\r\n    \"items\": [\r\n      373500489530470000\r\n    ]\r\n  },\r\n  \"location\": {\r\n    \"place\": \"Company name or information about pickup place e.g. garage\",\r\n    \"streetName\": \"streetname\",\r\n    \"streetNumber\": \"streetNumber\",\r\n    \"postalCode\": postalcode,\r\n    \"city\": \"txtCity\",\r\n    \"countryCode\": \"SE\"\r\n  },\r\n  \"order\": {\r\n    \"customerNumber\": \"1234567891\",\r\n    \"orderReference\": \"Ref-1212122A\",\r\n    \"contactName\": \"Nils Andersson\",\r\n    \"contactEmail\": \"[email protected]\",\r\n    \"phoneNumber\": \"+4670788888\",\r\n    \"smsNumber\": \"+4670788888\",\r\n    \"entryCode\": \"8216\"\r\n  },\r\n  \"pickup\": [\r\n    {\r\n      \"typeOfItem\": \"parcel\",\r\n      \"noUnits\": 1\r\n    }\r\n  ],\r\n  \"dateAndTimes\": {\r\n    \"readyPickupDate\": \"2020-11-17T09:52:07.929Z\",\r\n    \"latestPickupDate\": \"2020-11-17T09:52:07.929Z\",\r\n    \"earliestPickupDate\": \"2020-11-17T09:52:07.929Z\"\r\n  }\r\n}", ParameterType.RequestBody);


                request.AddHeader("Accept", "application/json");
                request.Parameters.Clear();



                string json  = JsonConvert.SerializeObject(shipment2, Formatting.Indented);
                string json2 = JsonConvert.SerializeObject(Shipmentbody, Formatting.Indented);
                string json3 = JsonConvert.SerializeObject(location2, Formatting.Indented);
                string json4 = JsonConvert.SerializeObject(Order2, Formatting.Indented);
                string json5 = JsonConvert.SerializeObject(PickUp2, Formatting.Indented);
                string json6 = JsonConvert.SerializeObject(datesandtimes2, Formatting.Indented);

                await DisplayAlert("Alert", json + json2 + json3 + json4 + json5 + json6, "OK");

                Console.WriteLine(json + json2 + json3 + json4 + json5 + json6);

                request.RequestFormat = DataFormat.Json;

                request.AddJsonBody(shipment2);
                request.AddJsonBody(Shipmentbody);
                request.AddJsonBody(location2);
                request.AddJsonBody(Order2);
                request.AddJsonBody(PickUp2);
                request.AddJsonBody(datesandtimes2);

                IRestResponse response = client.Execute(request);
                await DisplayAlert("Alert", response.Content.ToString(), "OK");
            }
            catch (Exception ex)

            {
                Console.WriteLine(ex);
                await DisplayAlert("Alert!", "Incorrect adress, try again", "OK");
            }
        }
Ejemplo n.º 9
0
 public Service3(Service2 service2)
 {
     _service2 = service2;
 }
Ejemplo n.º 10
0
 public PingController(Service1 service1, Service2 service2, Service3 service3)
 {
     Service1 = service1;
     Service2 = service2;
     Service3 = service3;
 }
Ejemplo n.º 11
0
        public void ServiceManager_Test02()
        {
            PropertyOwner propertyOwner   = new PropertyOwner();
            int           servicesAdded   = 0;
            int           servicesRemoved = 0;

            Service1 s1 = new Service1();
            Service2 s2 = new Service2();

            ServiceManager.AddService <IService1>(s1, propertyOwner, null);

            ServiceManager.GetService <IService1>(propertyOwner).Should().Be(s1);
            ServiceManager.GetService <Service1>(propertyOwner).Should().Be(s1);

            ServiceManager.RemoveService <IService1>(propertyOwner);
            ServiceManager.GetService <IService1>(propertyOwner).Should().BeNull();

            ServiceManager sm = ServiceManager.FromPropertyOwner(propertyOwner, null);

            sm.Should().NotBeNull();

            EventHandler <ServiceManagerEventArgs> onServiceAdded = (object sender, ServiceManagerEventArgs e) => {
                servicesAdded++;

                switch (servicesAdded)
                {
                case 1:
                    e.Service.Should().Be(s1);
                    e.ServiceType.Should().Be(typeof(IService1));
                    break;

                case 2:
                    e.Service.Should().Be(s2);
                    e.ServiceType.Should().Be(typeof(IService2));
                    break;
                }
            };

            EventHandler <ServiceManagerEventArgs> onServiceRemoved = (object sender, ServiceManagerEventArgs e) => {
                servicesRemoved++;

                switch (servicesRemoved)
                {
                case 1:
                    e.ServiceType.Should().Be(typeof(IService1));
                    break;

                case 2:
                    e.ServiceType.Should().Be(typeof(IService2));
                    break;
                }
            };

            sm.ServiceAdded   += onServiceAdded;
            sm.ServiceRemoved += onServiceRemoved;

            ServiceManager.AddService <IService1>(s1, propertyOwner, null);
            ServiceManager.AddService <IService2>(s2, propertyOwner, null);

            ServiceManager.RemoveService <IService1>(propertyOwner);
            ServiceManager.RemoveService <IService2>(propertyOwner);

            ServiceManager.GetService <IService1>(propertyOwner).Should().BeNull();
            ServiceManager.GetService <IService2>(propertyOwner).Should().BeNull();
        }
Ejemplo n.º 12
0
        public void Test2()
        {
            var service = new Service2();

            Assert.Equal(2, service.Call());
        }
Ejemplo n.º 13
0
 public static int Service2Test([FromServices] Service2 service2) => service2.Value;
Ejemplo n.º 14
0
 public RootClass(Service1 service1, Service2 service2)
     : this(service1, service2, "DEFAULT", 1976)
 {
 }
Ejemplo n.º 15
0
 public Service1(Service2 s2)
 {
     this.Service2 = s2;
 }
Ejemplo n.º 16
0
        public void Snapshot()
        {
            var services = new ServiceContainer();
            var service1 = new Service1();
            var service2 = new Service2();
            var service3 = new Service3();
            var snapshot = services.BuildServiceProvider();

            Assert.Empty(services);

            services.AddSingleton <IService1>(service1);
            services.AddSingleton <IService2>(service2);

            Assert.Equal(2, services.Count);

            Assert.Same(service1, services.GetService <IService1>());
            Assert.Same(service2, services.GetService <IService2>());
            Assert.Null(services.GetService <IService3>());

            Assert.Throws <InvalidOperationException>(() => services.GetRequiredService <IService3>());

            // These should all return NULL because the snapshot was
            // taken before the services were added.

            Assert.Null(snapshot.GetService <IService1>());
            Assert.Null(snapshot.GetService <IService2>());
            Assert.Null(snapshot.GetService <IService3>());

            // Get a new snapshot and test again.

            snapshot = services.BuildServiceProvider();

            Assert.Same(service1, services.GetService <IService1>());
            Assert.Same(service2, services.GetService <IService2>());
            Assert.Null(snapshot.GetService <IService3>());

            // Make sure that the [ServicesContainer] is still returning
            // the correct services.

            Assert.Same(service1, services.GetService <IService1>());
            Assert.Same(service2, services.GetService <IService2>());
            Assert.Null(services.GetService <IService3>());

            Assert.Throws <InvalidOperationException>(() => services.GetRequiredService <IService3>());

            // Add a third service and verify the [ServicesContainer].

            services.AddSingleton <IService3>(service3);

            Assert.Equal(3, services.Count);
            Assert.Same(service1, services.GetService <IService1>());
            Assert.Same(service2, services.GetService <IService2>());
            Assert.Same(service3, services.GetService <IService3>());

            // The new service shouldn't be in the last snapshot.

            Assert.Null(snapshot.GetService <IService3>());

            // Get a new snapshot and verify all three services.

            snapshot = services.BuildServiceProvider();

            Assert.Same(service1, services.GetService <IService1>());
            Assert.Same(service2, services.GetService <IService2>());
            Assert.Same(service3, services.GetService <IService3>());
        }