コード例 #1
0
 public NewParentCreatedEvent(Parent parent)
 {
     if (parent == null)
     {
         throw new ArgumentNullException("parent");
     }
     Parent = parent;
 }
コード例 #2
0
        public void SetUp()
        {
            parent = new Parent("Mike Hadlow", "*****@*****.**", "pwd");
            child = parent.CreateChild("Leo", "leohadlow", "xxx");

            somebodyElse = new Parent("John Robinson", "*****@*****.**", "pwd");
            somebodyElsesChild = somebodyElse.CreateChild("Jim", "jimrobinson", "yyy");
        }
コード例 #3
0
        public IEnumerable<Child> GetChildrenOf(Parent parent)
        {
            if (parent == null)
            {
                throw new ArgumentNullException("parent");
            }

            var childIds = parent.Children.Select(x => x.ChildId).ToArray();
            return session.Load<Child>(childIds).AsEnumerable();
        }
コード例 #4
0
ファイル: Child.cs プロジェクト: keithbloom/Suteki.TardisBank
        public void AcceptCashFromParent(Parent parent, decimal amount, string description)
        {
            var insufficientFundsMessage = string.Format(
                "You can not withdraw {0} because {1}'s account only has {2}",
                amount.ToString("c"),
                Name,
                Account.Balance.ToString("c"));

            WithdrawInternal(parent, amount, description, insufficientFundsMessage);
        }
コード例 #5
0
ファイル: Child.cs プロジェクト: keithbloom/Suteki.TardisBank
        public void WithdrawCashFromParent(Parent parent, decimal amount, string description)
        {
            var insufficientFundsMessage = string.Format(
                "You can not withdraw {0} because you only have {1} in your account",
                amount.ToString("c"),
                Account.Balance.ToString("c"));

            WithdrawInternal(parent, amount, description, insufficientFundsMessage);
            parent.SendMessage(string.Format("{0} would like to withdraw {1}", Name, amount.ToString("c")));
        }
コード例 #6
0
        public void WithdrawCashFromParent(Parent parent, decimal amount, string description)
        {
            var insufficientFundsMessage = string.Format(
                ResourceMessages.FormatCanNotWithdraw,
                amount.ToString("c"),
                Account.Balance.ToString("c"));

            WithdrawInternal(parent, amount, description, insufficientFundsMessage);
            parent.SendMessage(string.Format(ResourceMessages.FormatWouldLikeToWithdraw, Name, amount.ToString("c")));
        }
コード例 #7
0
        public void AcceptCashFromParent(Parent parent, decimal amount, string description)
        {
            var insufficientFundsMessage = string.Format(
                ResourceMessages.FormatCanNotWithdraw2,
                amount.ToString("c"),
                Name,
                Account.Balance.ToString("c"));

            WithdrawInternal(parent, amount, description, insufficientFundsMessage);
        }
コード例 #8
0
        public void Parent_should_raise_an_event_when_created()
        {
            NewParentCreatedEvent newParentCreatedEvent = null;
            using(DomainEvent.TestWith(e => { newParentCreatedEvent = (NewParentCreatedEvent)e; }))
            {
                var parent = new Parent("Dad", "*****@*****.**", "xxx").Initialise();

                newParentCreatedEvent.ShouldNotBeNull();
                newParentCreatedEvent.Parent.ShouldBeTheSameAs(parent);
            }
        }
コード例 #9
0
 string GetChildId()
 {
     using (var session = store.OpenSession())
     {
         var parent = new Parent("Mike Hadlow", "*****@*****.**", "yyy");
         var child = parent.CreateChild("Leo", "leohadlow", "xxx");
         session.Store(child);
         session.SaveChanges();
         return child.Id;
     }  
 }
コード例 #10
0
        public void SetUp()
        {
            parent = new Parent("Dad", "*****@*****.**", "xxx");
            child = parent.CreateChild("Leo", "leohadlow", "yyy");
            parent.MakePaymentTo(child, 10.00M);

            somebodyElsesParent = new Parent("Not Dad", "*****@*****.**", "zzz");

            // make sure these tests pass on non en-GB machines
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB");

            DomainEvent.TurnOff();
        }
コード例 #11
0
        string GetParentId(string name)
        {
            string parentId;

            using (var session = store.OpenSession())
            {
                var parent = new Parent(name: "Mike Hadlow", userName: string.Format("{0}@yahoo.com", name), password: "******");
                session.Store(parent);
                session.SaveChanges();
                parentId = parent.Id;
            }
            return parentId;
        }
コード例 #12
0
        void WithdrawInternal(Parent parent, decimal amount, string description, string insufficientFundsMessage)
        {
            if (parent == null)
            {
                throw new ArgumentNullException(ResourceMessages.MissingParentParameter);
            }
            if (description == null)
            {
                throw new ArgumentNullException(ResourceMessages.MissingDescriptionParameter);
            }

            if (!parent.HasChild(this))
            {
                throw new CashWithdrawException(ResourceMessages.NotYourParent);
            }

            if (amount > Account.Balance)
            {
                throw new CashWithdrawException(insufficientFundsMessage);
            }

            Account.AddTransaction(description, -amount);
        }
コード例 #13
0
        void CreateNewParentIfTheyDontAlreadyExist(IAuthenticationResponse response)
        {
            var userId = Model.User.UserIdFromUserName(response.ClaimedIdentifier);
            if (userService.GetUser(userId) != null) return;

            var parent = new Parent(response.FriendlyIdentifierForDisplay, response.ClaimedIdentifier, "todo");
            userService.SaveUser(parent);
        }
コード例 #14
0
        public bool AreNullOrNotRelated(Parent parent, Child child)
        {
            if (parent == null || child == null) return true;

            if (!parent.HasChild(child))
            {
                throw new TardisBankException("'{0}' is not a child of '{1}'", child.UserName, parent.UserName);
            }

            return false;
        }
コード例 #15
0
 public void SetUp()
 {
     store = NewDocumentStore();
     parent = new Parent("Dad", "*****@*****.**", "xxx");
 }
コード例 #16
0
 public void ParentShouldNotBeActiveWhenCreated()
 {
     User parent = new Parent("Dad", "*****@*****.**", "xxx");
     parent.IsActive.ShouldBeFalse();
 }
コード例 #17
0
 public void Child_should_be_active_when_created()
 {
     User child = new Parent("Dad", "*****@*****.**", "xxx").CreateChild("Leo", "leoahdlow", "bbb");
     child.IsActive.ShouldBeTrue();
 }