Exemplo n.º 1
0
        public void RunSubmitAdRequest()
        {
            var mockery = new MockRepository();
              var restClient = mockery.StrictMock<IRestClient>();
              var restRequestFactory = mockery.StrictMock<IRestRequestFactory>();
              var restRequest = mockery.StrictMock<IRestRequest>();
              var serializer = mockery.Stub<ISerializer>();

              var str = "some data";

              var adRequest = new AdRequest { NetworkId = Guid.NewGuid().ToString() };

              var ad = new AdvertisementMessage { id = "test" };
              var ads = new List<AdvertisementMessage> { ad };
              var advertisementResponse = new AdvertisementResponseMessage { advertisement = ads };
              var restResponse = new RestResponse<AdvertisementResponseMessage>();
              restResponse.Data = advertisementResponse;

              using (mockery.Record()) {
            Expect.Call(restRequestFactory.Create(null, Method.POST))
              .Constraints(Is.Anything(), Is.Equal(Method.POST))
              .Return(restRequest);
            restRequest.RequestFormat = DataFormat.Json;
            Expect.Call(restRequest.JsonSerializer).Return(serializer);
            Expect.Call(serializer.Serialize(null)).Constraints(
              Rhino.Mocks.Constraints.Property.Value("network_id", adRequest.NetworkId) &&
              Is.TypeOf<AdRequestMessage>()
            ).Return(str);
            Expect.Call(restRequest.AddParameter("text/json", str, ParameterType.RequestBody)).Return(new RestRequest());
            Expect.Call(restClient.Execute<AdvertisementResponseMessage>(restRequest)).Return(restResponse);
              }

              using (mockery.Playback()) {
            var results = new AdRequestor(restClient, restRequestFactory).RunSubmitAdRequest(adRequest);
            Assert.AreEqual(ad.id, results[0].Id);
              }
        }
Exemplo n.º 2
0
 internal static Advertisement FromMessage(AdvertisementMessage message)
 {
     return new Advertisement {
     Id = message.id,
     ProofOfPlayUrl = message.proof_of_play_url,
     ExpirationUrl = message.expiration_url,
     LeaseExpiry = message.lease_expiry,
     DisplayAreaId = message.display_area_id,
     AssetId = message.asset_id,
     AssetUrl = message.asset_url,
     Width = message.width,
     Height = message.height,
     MimeType = message.mime_type,
     LengthInSeconds = message.length_in_seconds,
     DisplayTime = message.display_time,
       };
 }