Esempio n. 1
0
        public async Task Publish_Publish_NotPublished_PublishesRealEstate()
        {
            Http.RespondWith(m =>
            {
                Assert.Equal("GET", m);
                return(new publishObjects {
                    publishObject = new PublishObject[] { }
                });
            }).ThenWith(m =>
            {
                Assert.Equal("POST", m);
                var po = new BaseXmlDeserializer().Deserialize <PublishObject>(new RestResponse {
                    Content = Http.RequestBody
                });
                Assert.Equal(4711, po.realEstate.id);
                Assert.Equal(ImportExportClient.ImmobilienscoutPublishChannelId, po.publishChannel.id);
                return(new messages {
                    message = new[] { new Message {
                                          messageCode = MessageCode.MESSAGE_RESOURCE_CREATED, message = "Publish Object with id [4711] has been created."
                                      } }
                });
            });

            await Client.Publish.PublishAsync(new ApartmentRent { id = 4711, idSpecified = true });
        }
Esempio n. 2
0
        public async Task Attachment_Create_HasMetadata()
        {
            Http.RespondWith(m =>
            {
                var meta = Http.Files.Single(f => f.Name == "metadata");
                Assert.Equal("application/xml", meta.ContentType);
                Assert.Equal("body.xml", meta.FileName);
                var ms = new MemoryStream();
                meta.Writer(ms);
                var bytes = ms.ToArray();
                Assert.Equal(bytes.Length, meta.ContentLength);
                var content = Encoding.UTF8.GetString(bytes);
                var a       = new BaseXmlDeserializer().Deserialize <Attachment>(new RestResponse {
                    Content = content
                });
                Assert.IsType <Picture>(a);
                Assert.Equal("Test", a.title);

                return(new messages {
                    message = new[] { new Message {
                                          messageCode = MessageCode.MESSAGE_RESOURCE_CREATED, message = "Resource with id [4711] has been created."
                                      } }
                });
            });

            await realEstate.Attachments.CreateAsync(new Picture { title = "Test" }, @"..\..\test.jpg");
        }
Esempio n. 3
0
        public async Task Publish_Publish_NotPublished_PublishesRealEstate()
        {
            Http.RespondWith(m =>
            {
                Assert.Equal("GET", m);
                return new PublishObjects { PublishObject = { } };
            }).ThenWith(m =>
            {
                Assert.Equal("POST", m);
                var po = new BaseXmlDeserializer().Deserialize<PublishObject>(new RestResponse { Content = Http.RequestBody });
                Assert.Equal(4711, po.RealEstate.Id);
                Assert.Equal(ImportExportClient.ImmobilienscoutPublishChannelId, po.PublishChannel.Id);
                return new Messages { Message = { new Message { MessageCode = MessageCode.MESSAGE_RESOURCE_CREATED, MessageProperty = "Publish Object with id [4711] has been created.", Id = "4711" } } };
            });

            await Client.Publish.PublishAsync(new ApartmentRent { Id = 4711 });
        }
Esempio n. 4
0
        public async Task Publish_Publish_NotPublished_PublishesRealEstate()
        {
            Http.RespondWith(m =>
            {
                Assert.Equal("GET", m);
                return new publishObjects { publishObject = new PublishObject[] { } };
            }).ThenWith(m =>
            {
                Assert.Equal("POST", m);
                var po = new BaseXmlDeserializer().Deserialize<PublishObject>(new RestResponse { Content = Http.RequestBody });
                Assert.Equal(4711, po.realEstate.id);
                Assert.Equal(ImportExportClient.ImmobilienscoutPublishChannelId, po.publishChannel.id);
                return new messages { message = new[] { new Message { messageCode = MessageCode.MESSAGE_RESOURCE_CREATED, message = "Publish Object with id [4711] has been created." } } };
            });

            await Client.Publish.PublishAsync(new ApartmentRent { id = 4711, idSpecified = true });
        }
Esempio n. 5
0
        public async Task Attachment_Update_PostsAttachmentObject()
        {
            Http.RespondWith(m =>
            {
                var a = new BaseXmlDeserializer().Deserialize <Attachment>(new RestResponse {
                    Content = Http.RequestBody
                });
                Assert.IsAssignableFrom <Attachment>(a);
                Assert.Equal(1, a.id);
                return(new messages {
                    message = new[] { new Message {
                                          messageCode = MessageCode.MESSAGE_RESOURCE_UPDATED, message = ""
                                      } }
                });
            });

            await realEstate.Attachments.UpdateAsync(new Picture { id = 1, idSpecified = true });
        }
Esempio n. 6
0
        void Test <T>(string file)
        {
            var xmlSerializer   = new BaseXmlSerializer();
            var xmlDeserializer = new BaseXmlDeserializer();

            foreach (var suffix in new[] { "min", "max" })
            {
                var xml = File.ReadAllText($@"..\..\..\xml\{file}_{suffix}.xml");

                var deserializedObject = xmlDeserializer.Deserialize <T>(new RestResponse {
                    Content = xml
                });

                var serializedXml   = xmlSerializer.Serialize(deserializedObject);
                var deserializedXml = xmlDeserializer.Deserialize <T>(new RestResponse {
                    Content = serializedXml
                });
                AssertEx.Equal(deserializedObject, deserializedXml);
            }
        }
Esempio n. 7
0
        void Test <T>(string file)
        {
            var xmlSerializer   = new BaseXmlSerializer();
            var xmlDeserializer = new BaseXmlDeserializer();
            var folder          = Directory.GetCurrentDirectory();

            foreach (var suffix in new[] { "min", "max" })
            {
                var xml = File.ReadAllText(string.Format(@"{0}\xml\{1}_{2}.xml", folder, file, suffix));

                var deserializedObject = xmlDeserializer.Deserialize <T>(new RestResponse {
                    Content = xml
                });

                var serializedXml   = xmlSerializer.Serialize(deserializedObject);
                var deserializedXml = xmlDeserializer.Deserialize <T>(new RestResponse {
                    Content = serializedXml
                });
                AssertEx.Equal(deserializedObject, deserializedXml);
            }
        }
        public async Task Attachment_CreateLink_PostsAttachmentObject()
        {
            RestClient.RespondWith(r =>
            {
                var l = new BaseXmlDeserializer().Deserialize <Attachment>(new RestResponse {
                    Content = (string)r.Body()
                });;
                Assert.IsAssignableFrom <Link>(l);
                Assert.Equal("http://www.example.com", ((Link)l).Url);
                return(new Messages {
                    Message = { new Message {
                                    MessageCode = MessageCode.MESSAGE_RESOURCE_CREATED, MessageProperty = "Resource with id [4711] has been created.", Id = "4711"
                                } }
                });
            });

            var re = new RealEstateItem(new ApartmentRent {
                Id = 4711
            }, Client.Connection);
            await re.Attachments.CreateAsync(new Link { Url = "http://www.example.com" });
        }
        public async Task Attachment_Update_PostsAttachmentObject()
        {
            RestClient.RespondWith(r =>
            {
                var a = new BaseXmlDeserializer().Deserialize <Attachment>(new RestResponse {
                    Content = (string)r.Body()
                });
                Assert.IsAssignableFrom <Attachment>(a);
                Assert.Equal(1, a.Id);
                return(new Messages {
                    Message = { new Message {
                                    MessageCode = MessageCode.MESSAGE_RESOURCE_UPDATED, MessageProperty = ""
                                } }
                });
            });

            var re = new RealEstateItem(new ApartmentRent {
                Id = 4711
            }, Client.Connection);
            await re.Attachments.UpdateAsync(new Picture { Id = 1 });
        }
Esempio n. 10
0
        public async Task Attachment_CreateVideo_RequestsCorrectResource()
        {
            RestClient.RespondWith(r =>
            {
                Assert.Equal(Method.GET, r.Method);
                Assert.Equal("https://rest.sandbox-immobilienscout24.de/restapi/api/offer/v1.0/user/me/videouploadticket", RestClient.BuildUri(r).AbsoluteUri);
                return(new VideoUploadTicket {
                    Auth = "secret", UploadUrl = "http://www.example.com/test", VideoId = "xyz"
                });
            }).ThenWith(r =>
            {
                Assert.Equal(Method.POST, r.Method);
                Assert.Equal("secret", (string)r.Parameters.Single(p => p.Name == "auth").Value);
                Assert.Equal("http://www.example.com/test", RestClient.BuildUri(r).AbsoluteUri);
                return("ok");
            }).ThenWith(r =>
            {
                Assert.Equal(Method.POST, r.Method);
                var v = new BaseXmlDeserializer().Deserialize <Attachment>(new RestResponse {
                    Content = (string)r.Body()
                });;
                Assert.Equal("xyz", ((StreamingVideo)v).VideoId);
                Assert.Equal("Video", ((StreamingVideo)v).Title);
                Assert.Equal("https://rest.sandbox-immobilienscout24.de/restapi/api/offer/v1.0/user/me/realestate/4711/attachment", RestClient.BuildUri(r).AbsoluteUri);
                return(new Messages {
                    Message = { new Message {
                                    MessageCode = MessageCode.MESSAGE_RESOURCE_CREATED, MessageProperty = "Resource with id [4711] has been created.", Id = "4711"
                                } }
                });
            });

            var video = new StreamingVideo {
                Title = "Video"
            };
            var re = new RealEstateItem(new ApartmentRent {
                Id = 4711
            }, Client.Connection);
            await re.Attachments.CreateStreamingVideoAsync(video, @"..\..\..\test.avi");
        }
Esempio n. 11
0
        public async Task OnTopPlacement_Create_CallSucceeds()
        {
            Http.RespondWith(m =>
            {
                var e = new BaseXmlDeserializer().Deserialize<Topplacements>(new RestResponse { Content = Http.RequestBody });
                Assert.IsType<Topplacements>(e);
                Assert.Equal(1, e.Topplacement.Count);
                Assert.Equal("1", e.Topplacement.Single().Realestateid);

                return new Topplacements
                {
                    Topplacement = { new Topplacement { Realestateid = "1",
                        MessageCode = MessageCode.MESSAGE_OPERATION_SUCCESSFUL, Message = "top placed"  } }
                };
            });

            var placements = new Topplacements { Topplacement = { new Topplacement { Realestateid = "1" } } };
            var result = await Client.TopPlacements.CreateAsync(placements);

            Assert.Equal(MessageCode.MESSAGE_OPERATION_SUCCESSFUL, result.Topplacement.Single().MessageObject.MessageCode);
            Assert.Equal("1", result.Topplacement.Single().Realestateid);
        }
Esempio n. 12
0
        public async Task Contact_Update_PostsRealEstateObject()
        {
            Http.RespondWith(m =>
            {
                var c = new BaseXmlDeserializer().Deserialize <RealtorContactDetails>(new RestResponse {
                    Content = Http.RequestBody
                });
                Assert.IsType <RealtorContactDetails>(c);
                Assert.Equal(4711, c.id);
                return(new messages {
                    message = new[] { new Message {
                                          messageCode = MessageCode.MESSAGE_RESOURCE_UPDATED, message = ""
                                      } }
                });
            });

            var contact = new RealtorContactDetails {
                id = 4711, idSpecified = true
            };

            await Client.Contacts.UpdateAsync(contact);
        }
Esempio n. 13
0
        public async Task Contact_Create_PostsRealtorObject()
        {
            Http.RespondWith(m =>
            {
                var c = new BaseXmlDeserializer().Deserialize <RealtorContactDetails>(new RestResponse {
                    Content = Http.RequestBody
                });
                Assert.IsType <RealtorContactDetails>(c);
                Assert.Equal("Meiser", c.lastname);
                return(new messages {
                    message = new[] { new Message {
                                          messageCode = MessageCode.MESSAGE_RESOURCE_CREATED, message = "Contact with id [4711] has been created."
                                      } }
                });
            });

            var contact = new RealtorContactDetails {
                lastname = "Meiser"
            };

            await Client.Contacts.CreateAsync(contact);
        }
Esempio n. 14
0
        public async Task RealEstate_Update_PostsRealEstateObject()
        {
            Http.RespondWith(m =>
            {
                var re = new BaseXmlDeserializer().Deserialize <RealEstate>(new RestResponse {
                    Content = Http.RequestBody
                });
                Assert.IsType <ApartmentRent>(re);
                Assert.Equal(4711, re.id);
                return(new messages {
                    message = new[] { new Message {
                                          messageCode = MessageCode.MESSAGE_RESOURCE_UPDATED, message = ""
                                      } }
                });
            });

            var r = new ApartmentRent {
                id = 4711, idSpecified = true, title = "Test"
            };

            await Client.RealEstates.UpdateAsync(r);
        }
Esempio n. 15
0
        public async Task RealEstate_Create_PostsRealEstateObject()
        {
            Http.RespondWith(m =>
            {
                var re = new BaseXmlDeserializer().Deserialize <RealEstate>(new RestResponse {
                    Content = Http.RequestBody
                });
                Assert.IsType <ApartmentRent>(re);
                Assert.Equal("Test", re.title);
                return(new messages {
                    message = new[] { new Message {
                                          messageCode = MessageCode.MESSAGE_RESOURCE_CREATED, message = "RealEstate with id [4711] has been created."
                                      } }
                });
            });

            var r = new ApartmentRent {
                title = "Test"
            };

            await Client.RealEstates.CreateAsync(r);
        }
Esempio n. 16
0
        public async Task Attachment_CreateLink_PostsAttachmentObject()
        {
            Http.RespondWith(m =>
            {
                var l = new BaseXmlDeserializer().Deserialize<Attachment>(new RestResponse { Content = Http.RequestBody });
                Assert.IsAssignableFrom<Link>(l);
                Assert.Equal("http://www.example.com", ((Link)l).Url);
                return new Messages { Message = { new Message { MessageCode = MessageCode.MESSAGE_RESOURCE_CREATED, MessageProperty = "Resource with id [4711] has been created.", Id = "4711" } } };
            });

            var re = new RealEstateItem(new ApartmentRent { Id = 4711 }, Client.Connection);
            await re.Attachments.CreateAsync(new Link { Url = "http://www.example.com" });
        }
Esempio n. 17
0
        public async Task Attachment_Update_PostsAttachmentObject()
        {
            Http.RespondWith(m =>
            {
                var a = new BaseXmlDeserializer().Deserialize<Attachment>(new RestResponse { Content = Http.RequestBody });
                Assert.IsAssignableFrom<Attachment>(a);
                Assert.Equal(1, a.id);
                return new messages { message = new[] { new Message { messageCode = MessageCode.MESSAGE_RESOURCE_UPDATED, message = "" } } };
            });

            await realEstate.Attachments.UpdateAsync(new Picture { id = 1, idSpecified = true });
        }
Esempio n. 18
0
        public async Task RealEstate_Update_PostsRealEstateObject()
        {
            Http.RespondWith(m =>
            {
                var re = new BaseXmlDeserializer().Deserialize<RealEstate>(new RestResponse { Content = Http.RequestBody });
                Assert.IsType<ApartmentRent>(re);
                Assert.Equal(4711, re.id);
                return new messages { message = new[] { new Message { messageCode = MessageCode.MESSAGE_RESOURCE_UPDATED, message = "" } } };
            });

            var r = new ApartmentRent { id = 4711, idSpecified = true, title = "Test" };

            await Client.RealEstates.UpdateAsync(r);
        }
Esempio n. 19
0
        public async Task SyncWorks()
        {
            RestClient.RespondWith(r =>
            {
                Assert.Equal(Method.GET, r.Method);
                Assert.Equal("https://rest.sandbox-immobilienscout24.de/restapi/api/offer/v1.0/user/me/realestate/4711/attachment", RestClient.BuildUri(r).AbsoluteUri);
                return(new Attachments
                {
                    Attachment =
                    {
                        new Picture        {
                            Id = 1, ExternalId = "Z0", Title = "Zimmer 0", ExternalCheckSum = "9c2210b068d609fb655f1c3423698dd1"
                        },
                        new Picture        {
                            Id = 2, ExternalId = "Z2", Title = "Zimmer 2", ExternalCheckSum = "4711"
                        },
                        new Picture        {
                            Id = 30, ExternalId = "Z3", Title = "Zimmer 3", ExternalCheckSum = "9c2210b068d609fb655f1c3423698dd1"
                        },
                        new StreamingVideo {
                            Id = 3, ExternalId = "817725e73569630898538fda4b22d0b9", Title = "Video", ExternalCheckSum = "bb84e757201eba7d1840153179297e8a"
                        },
                        new PDFDocument    {
                            Id = 4, ExternalId = "P1", Title = "Test", ExternalCheckSum = "24c43a4388ae2ea98322fa7016dd3274"
                        },
                        new Link           {
                            Id = 5, ExternalId = "L1", Title = "Test", Url = "http://www.example.com/"
                        }
                    }
                });
            }).ThenWith(r =>
            {
                Assert.Equal(Method.DELETE, r.Method);
                Assert.Equal("https://rest.sandbox-immobilienscout24.de/restapi/api/offer/v1.0/user/me/realestate/4711/attachment/1", RestClient.BuildUri(r).ToString());
                return(new Messages {
                    Message = { new Message {
                                    MessageCode = MessageCode.MESSAGE_RESOURCE_DELETED, MessageProperty = ""
                                } }
                });
            }).ThenWith(r =>
            {
                Assert.Equal(Method.DELETE, r.Method);
                Assert.Equal("https://rest.sandbox-immobilienscout24.de/restapi/api/offer/v1.0/user/me/realestate/4711/attachment/2", RestClient.BuildUri(r).ToString());
                return(new Messages {
                    Message = { new Message {
                                    MessageCode = MessageCode.MESSAGE_RESOURCE_DELETED, MessageProperty = ""
                                } }
                });
            }).ThenWith(r =>
            {
                Assert.Equal(Method.POST, r.Method);
                Assert.Equal("https://rest.sandbox-immobilienscout24.de/restapi/api/offer/v1.0/user/me/realestate/4711/attachment", RestClient.BuildUri(r).AbsoluteUri);
                var meta = r.Files.Single(f => f.Name == "metadata");
                Assert.Equal("application/xml", meta.ContentType);
                Assert.Equal("body.xml", meta.FileName);
                var ms = new MemoryStream();
                meta.Writer(ms);
                var bytes = ms.ToArray();
                Assert.Equal(bytes.Length, meta.ContentLength);
                var content = Encoding.UTF8.GetString(bytes);
                var a       = new BaseXmlDeserializer().Deserialize <Attachment>(new RestResponse {
                    Content = content
                });
                Assert.IsAssignableFrom <Attachment>(a);
                Assert.Equal("Zimmer 1", a.Title);
                return(new Messages {
                    Message = { new Message {
                                    MessageCode = MessageCode.MESSAGE_RESOURCE_CREATED, MessageProperty = "Resource with id [6] has been created.", Id = "6"
                                } }
                });
            }).ThenWith(r =>
            {
                Assert.Equal(Method.POST, r.Method);
                Assert.Equal("https://rest.sandbox-immobilienscout24.de/restapi/api/offer/v1.0/user/me/realestate/4711/attachment", RestClient.BuildUri(r).AbsoluteUri);
                var meta = r.Files.Single(f => f.Name == "metadata");
                Assert.Equal("application/xml", meta.ContentType);
                Assert.Equal("body.xml", meta.FileName);
                var ms = new MemoryStream();
                meta.Writer(ms);
                var bytes = ms.ToArray();
                Assert.Equal(bytes.Length, meta.ContentLength);
                var content = Encoding.UTF8.GetString(bytes);
                var a       = new BaseXmlDeserializer().Deserialize <Attachment>(new RestResponse {
                    Content = content
                });
                Assert.IsAssignableFrom <Attachment>(a);
                Assert.Equal("Zimmer 2", a.Title);
                return(new Messages {
                    Message = { new Message {
                                    MessageCode = MessageCode.MESSAGE_RESOURCE_CREATED, MessageProperty = "Resource with id [7] has been created.", Id = "7"
                                } }
                });
            }).ThenWith(r =>
            {
                Assert.Equal(Method.PUT, r.Method);
                Assert.Equal("https://rest.sandbox-immobilienscout24.de/restapi/api/offer/v1.0/user/me/realestate/4711/attachment/4", RestClient.BuildUri(r).AbsoluteUri);
                var a = new BaseXmlDeserializer().Deserialize <Attachment>(new RestResponse {
                    Content = (string)r.Body()
                });;
                Assert.IsAssignableFrom <Attachment>(a);
                Assert.Equal("Test Update", a.Title);
                return(new Messages {
                    Message = { new Message {
                                    MessageCode = MessageCode.MESSAGE_RESOURCE_UPDATED, MessageProperty = ""
                                } }
                });
            }).ThenWith(r =>
            {
                Assert.Equal(Method.GET, r.Method);
                Assert.Equal("https://rest.sandbox-immobilienscout24.de/restapi/api/offer/v1.0/user/me/realestate/4711/attachment/attachmentsorder", RestClient.BuildUri(r).ToString());
                return(new AttachmentsOrder.List {
                    AttachmentId = { 30, 4, 6, 7 }
                });
            }).ThenWith(r =>
            {
                Assert.Equal(Method.PUT, r.Method);
                Assert.Equal("https://rest.sandbox-immobilienscout24.de/restapi/api/offer/v1.0/user/me/realestate/4711/attachment/attachmentsorder", RestClient.BuildUri(r).AbsoluteUri);
                var list = r.Body() as AttachmentsOrder.List;
                Assert.IsAssignableFrom <AttachmentsOrder.List>(list);
                AssertEx.CollectionEqual <long>(new long[] { 6, 7, 4, 30 }, list.AttachmentId);
                return(new Messages {
                    Message = { new Message {
                                    MessageCode = MessageCode.MESSAGE_RESOURCE_UPDATED, MessageProperty = ""
                                } }
                });
            });

            var re = new RealEstateItem(new ApartmentRent {
                Id = 4711
            }, Client.Connection);
            var a1 = new KeyValuePair <Attachment, string>(new Picture {
                ExternalId = "Z1", Title = "Zimmer 1"
            }, @"..\..\..\test.jpg");
            var a2 = new KeyValuePair <Attachment, string>(new Picture {
                ExternalId = "Z2", Title = "Zimmer 2"
            }, @"..\..\..\test.jpg");
            var a3 = new KeyValuePair <Attachment, string>(new Picture {
                ExternalId = "Z3", Title = "Zimmer 3"
            }, @"..\..\..\test.jpg");
            var pdf = new KeyValuePair <Attachment, string>(new PDFDocument {
                ExternalId = "P1", Title = "Test Update"
            }, @"..\..\..\test.pdf");
            var video = new KeyValuePair <Attachment, string>(new StreamingVideo {
                Title = "Video"
            }, @"..\..\..\test.avi");
            var link = new KeyValuePair <Attachment, string>(new Link {
                Title = "Test", Url = "http://www.example.com/"
            }, null);
            var atts = new[] { a1, link, video, a2, pdf, a3 };

            await re.Attachments.UpdateAsync(atts);

            Assert.Equal("817725e73569630898538fda4b22d0b9", video.Key.ExternalId);
            Assert.Equal(4, pdf.Key.Id);
            Assert.Equal(6, a1.Key.Id);
            Assert.Equal(7, a2.Key.Id);
            Assert.Equal(3, video.Key.Id);
            Assert.Equal(5, link.Key.Id);
            Assert.Equal("9c2210b068d609fb655f1c3423698dd1", a1.Key.ExternalCheckSum);
            Assert.Equal("9c2210b068d609fb655f1c3423698dd1", a2.Key.ExternalCheckSum);
            Assert.Equal("bb84e757201eba7d1840153179297e8a", video.Key.ExternalCheckSum);
            Assert.Equal("24c43a4388ae2ea98322fa7016dd3274", pdf.Key.ExternalCheckSum);
        }
Esempio n. 20
0
        public async Task RealEstate_Create_PostsRealEstateObject()
        {
            Http.RespondWith(m =>
            {
                var re = new BaseXmlDeserializer().Deserialize<RealEstate>(new RestResponse { Content = Http.RequestBody });
                Assert.IsType<ApartmentRent>(re);
                Assert.Equal("Test", re.title);
                return new messages { message = new[] { new Message { messageCode = MessageCode.MESSAGE_RESOURCE_CREATED, message = "RealEstate with id [4711] has been created." } } };
            });

            var r = new ApartmentRent { title = "Test" };

            await Client.RealEstates.CreateAsync(r);
        }
Esempio n. 21
0
        public async Task Attachment_Update_PostsAttachmentObject()
        {
            Http.RespondWith(m =>
            {
                var a = new BaseXmlDeserializer().Deserialize<Attachment>(new RestResponse { Content = Http.RequestBody });
                Assert.IsAssignableFrom<Attachment>(a);
                Assert.Equal(1, a.Id);
                return new Messages { Message = { new Message { MessageCode = MessageCode.MESSAGE_RESOURCE_UPDATED, MessageProperty = "" } } };
            });

            var re = new RealEstateItem(new ApartmentRent { Id = 4711 }, Client.Connection);
            await re.Attachments.UpdateAsync(new Picture { Id = 1 });
        }
Esempio n. 22
0
        public async Task AttachmentsOrder_Update_PostsAttachmentObject()
        {
            Http.RespondWith(m =>
            {
                var list = new BaseXmlDeserializer().Deserialize<AttachmentsOrder.List>(new RestResponse { Content = Http.RequestBody });
                Assert.IsAssignableFrom<AttachmentsOrder.List>(list);
                AssertEx.CollectionEqual<long>(new long[] { 3, 2, 1 }, list.AttachmentId);
                return new Messages { Message = { new Message { MessageCode = MessageCode.MESSAGE_RESOURCE_UPDATED, MessageProperty = "" } } };
            });

            var re = new RealEstateItem(new ApartmentRent { Id = 4711 }, Client.Connection);
            await re.Attachments.AttachmentsOrder.UpdateAsync(new AttachmentsOrder.List { AttachmentId = { 3, 2, 1 } });
        }
Esempio n. 23
0
        public async Task RealEstateProject_Create_CallSucceeds()
        {
            Http.RespondWith(m =>
            {
                var e = new BaseXmlDeserializer().Deserialize<RealEstateProjectEntries>(new RestResponse { Content = Http.RequestBody });
                Assert.IsType<RealEstateProjectEntries>(e);
                Assert.Equal(1, e.RealEstateProjectEntry.Count);
                Assert.Equal(1, e.RealEstateProjectEntry.Single().RealEstateId);

                return new RealEstateProjectEntries
                {
                    RealEstateProjectEntry = { new RealEstateProjectEntry { RealEstateId = 1,
                        MessageCode = MessageCode.MESSAGE_RESOURCE_CREATED, Message = "real estate with id 1 was added to project 4711"  } }
                };
            });

            var entries = new RealEstateProjectEntries { RealEstateProjectEntry = { new RealEstateProjectEntry { RealEstateId = 1 } } };
            var result = await Client.RealEstateProjects.AddAsync(4711, entries);

            Assert.Equal(MessageCode.MESSAGE_RESOURCE_CREATED, result.RealEstateProjectEntry.Single().MessageObject.MessageCode);
            Assert.Equal(1, result.RealEstateProjectEntry.Single().RealEstateId);
        }
Esempio n. 24
0
        public async Task Contact_Update_PostsRealEstateObject()
        {
            Http.RespondWith(m =>
            {
                var c = new BaseXmlDeserializer().Deserialize<RealtorContactDetails>(new RestResponse { Content = Http.RequestBody });
                Assert.IsType<RealtorContactDetails>(c);
                Assert.Equal(4711, c.Id);
                return new Messages { Message = { new Message { MessageCode = MessageCode.MESSAGE_RESOURCE_UPDATED, MessageProperty = "" } } };
            });

            var contact = new RealtorContactDetails { Id = 4711 };

            await Client.Contacts.UpdateAsync(contact);
        }
Esempio n. 25
0
        public async Task Contact_Create_PostsRealtorObject()
        {
            Http.RespondWith(m =>
            {
                var c = new BaseXmlDeserializer().Deserialize<RealtorContactDetails>(new RestResponse { Content = Http.RequestBody });
                Assert.IsType<RealtorContactDetails>(c);
                Assert.Equal("Meiser", c.Lastname);
                return new Messages { Message = { new Message { MessageCode = MessageCode.MESSAGE_RESOURCE_CREATED, MessageProperty = "Contact with id [4711] has been created.", Id = "4711" } } };
            });

            var contact = new RealtorContactDetails { Lastname = "Meiser" };

            await Client.Contacts.CreateAsync(contact);
        }
Esempio n. 26
0
        public async Task Attachment_Create_HasMetadata()
        {
            Http.RespondWith(m =>
            {
                var meta = Http.Files.Single(f => f.Name == "metadata");
                Assert.Equal("application/xml", meta.ContentType);
                Assert.Equal("body.xml", meta.FileName);
                var ms = new MemoryStream();
                meta.Writer(ms);
                var bytes = ms.ToArray();
                Assert.Equal(bytes.Length, meta.ContentLength);
                var content = Encoding.UTF8.GetString(bytes);
                var a = new BaseXmlDeserializer().Deserialize<Attachment>(new RestResponse { Content = content });
                Assert.IsType<Picture>(a);
                Assert.Equal("Test", a.Title);

                return new Messages { Message = { new Message { MessageCode = MessageCode.MESSAGE_RESOURCE_CREATED, MessageProperty = "Resource with id [4711] has been created.", Id = "4711" } } };
            });

            var re = new RealEstateItem(new ApartmentRent { Id = 4711 }, Client.Connection);
            await re.Attachments.CreateAsync(new Picture { Title = "Test" }, @"..\..\test.jpg");
        }
Esempio n. 27
0
        public async Task Contact_Update_ExternalIdIsUsedIfIdIsNull()
        {
            Http.RespondWith(m =>
            {
                Assert.Equal("http://rest.sandbox-immobilienscout24.de/restapi/api/offer/v1.0/user/me/contact/ext-test", Http.Url.ToString());
                var c = new BaseXmlDeserializer().Deserialize<RealtorContactDetails>(new RestResponse { Content = Http.RequestBody });
                Assert.IsType<RealtorContactDetails>(c);
                Assert.Null(c.Id);
                return new Messages { Message = { new Message { MessageCode = MessageCode.MESSAGE_RESOURCE_UPDATED, MessageProperty = "" } } };
            });

            var contact = new RealtorContactDetails { ExternalId = "test" };

            await Client.Contacts.UpdateAsync(contact);
        }
Esempio n. 28
0
        public async Task Attachment_CreateVideo_RequestsCorrectResource()
        {
            Http.RespondWith(m =>
            {
                Assert.Equal("GET", m);
                Assert.Equal("http://rest.sandbox-immobilienscout24.de/restapi/api/offer/v1.0/user/me/videouploadticket", Http.Url.AbsoluteUri);
                return new VideoUploadTicket { Auth = "secret", UploadUrl = "http://www.example.com/test", VideoId = "xyz" };
            }).ThenWith(m =>
            {
                Assert.Equal("POST", m);
                Assert.Equal("secret", Http.Parameters.Single(p => p.Name == "auth").Value);
                Assert.Equal("http://www.example.com/test", Http.Url.AbsoluteUri);
                return "ok";
            }).ThenWith(m =>
            {
                Assert.Equal("POST", m);
                var v = new BaseXmlDeserializer().Deserialize<Attachment>(new RestResponse { Content = Http.RequestBody });
                Assert.Equal("xyz", ((StreamingVideo)v).VideoId);
                Assert.Equal("Video", ((StreamingVideo)v).Title);
                Assert.Equal("http://rest.sandbox-immobilienscout24.de/restapi/api/offer/v1.0/user/me/realestate/4711/attachment", Http.Url.AbsoluteUri);
                return new Messages { Message = { new Message { MessageCode = MessageCode.MESSAGE_RESOURCE_CREATED, MessageProperty = "Resource with id [4711] has been created.", Id = "4711" } } };
            });

            var video = new StreamingVideo { Title = "Video" };
            var re = new RealEstateItem(new ApartmentRent { Id = 4711 }, Client.Connection);
            await re.Attachments.CreateStreamingVideoAsync(video, @"..\..\test.avi");
        }