Skip to content

Commit

Permalink
MessageManager 项目调整,领域模型测试用例编写
Browse files Browse the repository at this point in the history
  • Loading branch information
yuezhongxin committed Jul 14, 2014
1 parent 5b11aaa commit 533f41a
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 44 deletions.
74 changes: 72 additions & 2 deletions MessageManager.Domain.Tests/MessageDomainTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using MessageManager.Domain.DomainService;
using MessageManager.Domain.Entity;
using MessageManager.Domain.ValueObject;
using System;
using Xunit;

namespace MessageManager.Domain.Tests
Expand All @@ -19,10 +20,79 @@ public class MessageDomainTest
public void DomainTest_SendShortMessage()
{
ISendMessageService sendMessageService = new SendShortMessageService();
IContact sender = new Sender("1");
IContact recipient = new Recipient("123");
IContact sender = new Sender("sender");
IContact recipient = new Recipient("recipient");
Message message = new Message("title", "content ", sender, recipient);
Assert.True(sendMessageService.SendMessage(message));
}

/// <summary>
/// 阅读收件箱
/// </summary>
[Fact]
public void DomainTest_ReadInbox()
{
IContact recipient = new Recipient("recipient");
MessageBox inbox = new Inbox(recipient);
foreach (Message message in inbox.Messages)
{
Console.WriteLine("ID:" + message.ID);
Console.WriteLine("Title:" + message.Title);
Console.WriteLine("Content:" + message.Content);
Console.WriteLine("Sender:" + message.Sender.Name);
Console.WriteLine("Recipient:" + message.Recipient.Name);
Console.WriteLine("MessageState:" + (message.State == MessageState.NoRead ? "未读" : "已读"));
}
}

/// <summary>
/// 阅读发件箱
/// </summary>
[Fact]
public void DomainTest_ReadOutbox()
{
IContact sender = new Sender("sender");
MessageBox outbox = new Outbox(sender);
foreach (Message message in outbox.Messages)
{
Console.WriteLine("ID:" + message.ID);
Console.WriteLine("Title:" + message.Title);
Console.WriteLine("Content:" + message.Content);
Console.WriteLine("Sender:" + message.Sender.Name);
Console.WriteLine("Recipient:" + message.Recipient.Name);
Console.WriteLine("MessageState:" + (message.State == MessageState.NoRead ? "未读" : "已读"));
}
}

/// <summary>
/// 发送人阅读单条消息
/// </summary>
[Fact]
public void DomainTest_SenderReadMessage()
{
IContact sender = new Sender("sender");
Message message = new Outbox(sender).GetMessage("1");
Console.WriteLine("ID:" + message.ID);
Console.WriteLine("Title:" + message.Title);
Console.WriteLine("Content:" + message.Content);
Console.WriteLine("Sender:" + message.Sender.Name);
Console.WriteLine("Recipient:" + message.Recipient.Name);
Console.WriteLine("MessageState:" + (message.State == MessageState.NoRead ? "未读" : "已读"));
}

/// <summary>
/// 接收人阅读单条消息
/// </summary>
[Fact]
public void DomainTest_RecipientReadMessage()
{
IContact recipient = new Recipient("recipient");
Message message = new Inbox(recipient).GetMessage("1");
Console.WriteLine("Title:" + message.Title);
Console.WriteLine("Content:" + message.Content);
Console.WriteLine("Sender:" + message.Sender.Name);
Console.WriteLine("Recipient:" + message.Recipient.Name);
Console.WriteLine("MessageState:" + (message.State == MessageState.NoRead ? "未读" : "已读"));
}
}
}
20 changes: 0 additions & 20 deletions MessageManager.Domain/DomainService/GetInboxService.cs

This file was deleted.

31 changes: 31 additions & 0 deletions MessageManager.Domain/Entity/Inbox.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* author:xishuai
* address:https://www.github.com/yuezhongxin/MessageManager
**/

using MessageManager.Domain.ValueObject;
using System.Collections.Generic;
using System.Linq;

namespace MessageManager.Domain.Entity
{
public class Inbox : MessageBox
{
public Inbox(IContact recipient)
: base(recipient)
{
this.Messages = new List<Message>() { new Message("title", "title", new Sender("sender"), new Recipient("recipient")) };
}

public override Message GetMessage(string id)
{
//Message message = this.Messages.First(m => m.ID == id);
Message message = this.Messages.First();
if (message.State == MessageState.NoRead)
{
message.State = MessageState.Read;
}
return message;
}
}
}
5 changes: 2 additions & 3 deletions MessageManager.Domain/Entity/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ public Message(string title, string content, IContact sender, IContact recipient
{
throw new ArgumentException("recipient can't be null");
}
this.ID = Guid.NewGuid().ToString();
//this.ID = Guid.NewGuid().ToString();
this.ID = "1";
this.Title = title;
this.Content = content;
this.SendTime = DateTime.Now;
this.State = MessageState.NoRead;
this.Type = MessageType.OutboxAndInbox;
this.Sender = sender;
this.Recipient = recipient;
}
Expand All @@ -50,7 +50,6 @@ public Message(string title, string content, IContact sender, IContact recipient
public string Content { get; private set; }
public DateTime SendTime { get; private set; }
public MessageState State { get; set; }
public MessageType Type { get; set; }
public virtual IContact Sender { get; private set; }
public virtual IContact Recipient { get; private set; }
}
Expand Down
20 changes: 17 additions & 3 deletions MessageManager.Domain/Entity/MessageBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,31 @@
* address:https://www.github.com/yuezhongxin/MessageManager
**/

using MessageManager.Domain.ValueObject;
using System.Collections.Generic;
using System.Linq;

namespace MessageManager.Domain.Entity
{
public class MessageBox
public abstract class MessageBox
{
public MessageBox()
public MessageBox(IContact contact)
{
Messages = new List<Message>();
this.Contact = contact;
}

public IContact Contact { get; set; }
public ICollection<Message> Messages { get; set; }

public virtual Message GetMessage(string id)
{
return this.Messages.First();
//return this.Messages.First(m => m.ID == id);
}

public virtual bool RemoveMessage(string id)
{
return true;
}
}
}
19 changes: 19 additions & 0 deletions MessageManager.Domain/Entity/Outbox.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* author:xishuai
* address:https://www.github.com/yuezhongxin/MessageManager
**/

using MessageManager.Domain.ValueObject;
using System.Collections.Generic;

namespace MessageManager.Domain.Entity
{
public class Outbox : MessageBox
{
public Outbox(IContact sender)
: base(sender)
{
this.Messages = new List<Message>() { new Message("title", "title", new Sender("sender"), new Recipient("recipient")) };
}
}
}
4 changes: 2 additions & 2 deletions MessageManager.Domain/MessageManager.Domain.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@
</ItemGroup>
<ItemGroup>
<Compile Include="DomainService\IService\ISendMessageService.cs" />
<Compile Include="DomainService\GetInboxService.cs" />
<Compile Include="Entity\Message.cs" />
<Compile Include="Entity\MessageBox.cs" />
<Compile Include="Entity\Inbox.cs" />
<Compile Include="Entity\Outbox.cs" />
<Compile Include="ValueObject\MessageState.cs" />
<Compile Include="IAggregateRoot.cs" />
<Compile Include="IEntity.cs" />
Expand All @@ -67,7 +68,6 @@
<Compile Include="Specifications\OrSpecification.cs" />
<Compile Include="Specifications\ParameterRebinder.cs" />
<Compile Include="Specifications\Specification.cs" />
<Compile Include="ValueObject\MessageType.cs" />
<Compile Include="ValueObject\Sender.cs" />
<Compile Include="ValueObject\IContact.cs" />
</ItemGroup>
Expand Down
14 changes: 0 additions & 14 deletions MessageManager.Domain/ValueObject/MessageType.cs

This file was deleted.

0 comments on commit 533f41a

Please sign in to comment.