Exemplo n.º 1
0
        private void AddLibraryBtn_Click(object sender, RoutedEventArgs e)
        {
            InitDataSource(ref libraryItems, Mapper.LibrariesToLibraryViewModels, libraryController.Get);

            AddLibrary addLibrary = new AddLibrary();

            if (addLibrary.ShowDialog().Value)
            {
                string name        = addLibrary.Name.Text;
                string description = addLibrary.Description.Text;

                if (name != null)
                {
                    Library library = new Library(name, description);
                    libraryController.Add(library);
                    libraryItems.Add(Mapper.LibraryToLibraryViewModel(library));
                    return;
                }
            }
        }
        void adding_games_to_library()
        {
            before = () => finalFantasy7 = GivenGame("Final Fantasy 7", "PS2");

            act = () => result = controller.Add(new { gameId = finalFantasy7 });

            it["game is available to user"] = () => (Library().First().Name as string).should_be("Final Fantasy 7");

            it["returns the game that was added"] = () => (result.Data.Name as string).should_be("Final Fantasy 7");

            context["same game is added to library"] = () =>
            {
                act = () => controller.Add(new { gameId = finalFantasy7 });

                it["the game isn't added"] = () => Library().Count().should_be(1);
            };

            context["game libraries are unique accross users"] = () =>
            {
                before = () => GivenUserHasGame(anotherUser, finalFantasy7);

                it["game is available to user"] = () => (Library().First().Name as string).should_be("Final Fantasy 7");
            };

            context["friends are following the person who added the game"] = () =>
            {
                before = () =>
                {
                    GivenUserIsFollowing(anotherUser, user);
                    GivenUserIsFollowing(yetAnotherUser, user);
                };

                it["notification emails are sent to followers"] = () =>
                {
                    var email = emailsSent[0];

                    email.To.should_be(User(anotherUser).Email as string);

                    var subject = User(user).Handle as string + " added Final Fantasy 7 (PS2) to his library.";

                    email.Subject.should_be(subject);

                    email.Body.should_be(subject + Environment.NewLine + "Go check it out at http://borrowedgames.com/");

                    email = emailsSent[1];

                    email.To.should_be(User(yetAnotherUser).Email as string);

                    emailsSent.Count.should_be(2);
                };

                context["user adds another game the same day", "wip"] = () =>
                {
                    before = () => finalFantasyTactics = GivenGame("Final Fantasy Tactics", "PS2");

                    act = () =>
                    {
                        emailsSent.Count.should_be(2);
                        emailsSent.Clear();
                        controller.Add(new { gameId = finalFantasyTactics });
                    };

                    it["a subsequent email for that day is not sent"] = () =>
                        emailsSent.Count.should_be(0);
                };
            };
        }