Пример #1
0
        public void PostResponseDocuments()
        {
            DataContext db       = new DataContext();
            Response    response = null;

            try
            {
                RequestDataMart routing = db.RequestDataMarts.Include(dm => dm.Responses).Where(dm => dm.Status == DTO.Enums.RoutingStatus.Submitted && dm.Responses.Count > 0).OrderByDescending(dm => dm.RequestTime).FirstOrDefault();
                response = routing.AddResponse(db.Users.Where(u => u.UserName == TestDMCController.TestUserName).Select(u => u.ID).Single());
                db.SaveChanges();

                Guid[] result = null;
                using (var controller = new TestDMCController())
                {
                    var postData = new Lpp.Dns.DTO.DataMartClient.Criteria.PostResponseDocumentsData
                    {
                        RequestID  = routing.RequestID,
                        DataMartID = routing.DataMartID,
                        Documents  = new[] { new DTO.DataMartClient.Document {
                                                 Name = "test-document.txt", IsViewable = false, MimeType = "text/plain", Size = 0
                                             } }
                    };
                    result = AsyncHelpers.RunSync <Guid[]>(() => controller.PostResponseDocuments(postData));
                }

                Assert.IsNotNull(result);
                Assert.IsTrue(result.Count() > 0);

                Guid     documentID = result.ToArray().First();
                Document doc        = db.Documents.FirstOrDefault(d => d.ID == documentID);
                Assert.IsNotNull(doc);
            }
            finally
            {
                if (response != null)
                {
                    db.Documents.RemoveRange(db.Documents.Where(d => d.ItemID == response.ID));
                    db.Responses.Remove(response);
                    db.SaveChanges();
                }
                db.Dispose();
            }
        }
Пример #2
0
        public void PostResponseDocumentsWithContent()
        {
            const string string1 = "This is a test document.";
            const string string2 = " This is the second sentence.";

            byte[] string1Data = Encoding.Default.GetBytes(string1);
            byte[] string2Data = Encoding.Default.GetBytes(string2);

            DataContext db       = new DataContext();
            Response    response = null;

            try
            {
                RequestDataMart routing = db.RequestDataMarts.Include(dm => dm.Responses).Where(dm => dm.Status == DTO.Enums.RoutingStatus.Submitted && dm.Responses.Count > 0).OrderByDescending(dm => dm.RequestTime).FirstOrDefault();
                response             = routing.AddResponse(db.Users.Where(u => u.UserName == TestDMCController.TestUserName).Select(u => u.ID).Single());
                response.SubmittedOn = DateTime.Now;
                db.SaveChanges();

                Guid[] result = null;
                Guid   documentID;
                using (var controller = new TestDMCController())
                {
                    var postData = new Lpp.Dns.DTO.DataMartClient.Criteria.PostResponseDocumentsData {
                        RequestID  = routing.RequestID,
                        DataMartID = routing.DataMartID,
                        Documents  = new[] { new DTO.DataMartClient.Document {
                                                 Name = "test-document.txt", IsViewable = false, MimeType = "text/plain", Size = 0
                                             } }
                    };
                    result = AsyncHelpers.RunSync <Guid[]>(() => controller.PostResponseDocuments(postData));

                    documentID = result.ToArray()[0];
                    System.Net.Http.HttpResponseMessage postResponse = AsyncHelpers.RunSync <System.Net.Http.HttpResponseMessage>(() => controller.PostResponseDocumentChunk(documentID, string1Data));
                    Assert.IsTrue(postResponse.StatusCode == System.Net.HttpStatusCode.OK);
                    postResponse = AsyncHelpers.RunSync <System.Net.Http.HttpResponseMessage>(() => controller.PostResponseDocumentChunk(documentID, string2Data));
                    Assert.IsTrue(postResponse.StatusCode == System.Net.HttpStatusCode.OK);
                }

                Assert.IsNotNull(result);
                Assert.IsTrue(result.Count() > 0);

                Document doc = db.Documents.FirstOrDefault(d => d.ID == documentID);
                Assert.IsNotNull(doc);

                byte[] docData = doc.GetData(db);

                Assert.AreEqual(string1Data.Length + string2Data.Length, docData.Length);
                string savedString = Encoding.Default.GetString(docData);
                Console.WriteLine(savedString);
            }
            finally
            {
                if (response != null)
                {
                    db.Database.ExecuteSqlCommand("DELETE FROM Documents WHERE ItemID = @p0", response.ID);
                    db.Database.ExecuteSqlCommand("DELETE FROM RequestDataMartResponses WHERE ID = @p0", response.ID);
                    db.SaveChanges();
                }
                db.Dispose();
            }
        }