コード例 #1
0
ファイル: TestMDN.cs プロジェクト: wwj229/nhin-d.net35
        public void TestSerialization_Dispatched()
        {
            Disposition expectedDisposition = new Disposition(MDNStandard.NotificationType.Dispatched);

            Message             source              = this.CreateSourceMessage();
            Notification        notification        = this.CreateDispatchedNotification();
            NotificationMessage notificationMessage = source.CreateNotificationMessage(new MailAddress(source.FromValue), notification);

            var path = Path.GetTempFileName();

            try
            {
                notificationMessage.Save(path);
                Message loadedMessage = Message.Load(File.ReadAllText(path));
                Assert.True(loadedMessage.IsMDN());
                Assert.Equal(notificationMessage.ParsedContentType.MediaType, loadedMessage.ParsedContentType.MediaType);
                Assert.Equal(notificationMessage.SubjectValue, loadedMessage.SubjectValue);
                Assert.True(loadedMessage.HasHeader(MimeStandard.VersionHeader));
                Assert.True(loadedMessage.HasHeader(MailStandard.Headers.Date));
                Assert.True(loadedMessage.Headers.Count(x => (MimeStandard.Equals(x.Name, MimeStandard.VersionHeader))) == 1);
                var mdn = MDNParser.Parse(loadedMessage);
                VerifyEqual(expectedDisposition, mdn.Disposition);
            }
            finally
            {
                File.Delete(path);
            }
        }
コード例 #2
0
ファイル: TestMDN.cs プロジェクト: wwj229/nhin-d.net35
        public void TestExtensions_ExtensionsSerialization()
        {
            Disposition expectedDisposition = new Disposition(MDNStandard.NotificationType.Processed);

            Message      source       = this.CreateSourceMessage();
            Notification notification = this.CreateProcessedNotification();

            notification.SpecialFields = new HeaderCollection()
            {
                //Header value of empty fails JoinHeader in DefaultSerializer.  Research this...
                //Constructor with StringSegment does not fail.
                new Header(new StringSegment("X-Test1:")),
                new Header(new StringSegment("X-Test2:MyValue"))
            };
            notification.OriginalRecipient = new MailAddress("*****@*****.**");
            NotificationMessage notificationMessage = source.CreateNotificationMessage(new MailAddress(source.FromValue), notification);

            var path = Path.GetTempFileName();

            try
            {
                notificationMessage.Save(path);
                Message loadedMessage = Message.Load(File.ReadAllText(path));
                Assert.True(loadedMessage.IsMDN());
                Assert.Equal(notificationMessage.ParsedContentType.MediaType, loadedMessage.ParsedContentType.MediaType);
                Assert.Equal(notificationMessage.SubjectValue, loadedMessage.SubjectValue);
                Assert.True(loadedMessage.HasHeader(MimeStandard.VersionHeader));
                Assert.True(loadedMessage.HasHeader(MailStandard.Headers.Date));
                Assert.True(loadedMessage.Headers.Count(x => (MimeStandard.Equals(x.Name, MimeStandard.VersionHeader))) == 1);

                var mdn = MDNParser.Parse(loadedMessage);
                VerifyEqual(expectedDisposition, mdn.Disposition);
                Assert.NotNull(mdn.SpecialFields["X-Test1"]);
                Assert.Equal("", mdn.SpecialFields["X-Test1"].ValueRaw);
                Assert.Equal("MyValue", mdn.SpecialFields["X-Test2"].Value);
                Assert.Equal(notification.OriginalRecipient, mdn.OriginalRecipient);
            }
            finally
            {
                File.Delete(path);
            }
        }