示例#1
0
        // POST: /<controller>/Create
        public ActionResult Create(CreateLobbyViewModel viewModel)
        {
            using (var myWork = _factory.GetUOF())
            {
                // Perform data validation.
                if (!TryValidateModel(viewModel))
                {
                    // Errors, return and let the user handle it.
                    return(View(viewModel));
                }

                // Create the domain lobby object.
                var lobby = new Lobby()
                {
                    Name        = viewModel.Name,
                    Description = viewModel.Description,
                };

                // Save to the database.
                myWork.Lobby.Add(lobby);
                var aUser = myWork.User.Get(_userContext.Identity.Name);
                lobby.MemberList.Add(aUser);
                myWork.Complete();

                // Show the newly created lobby.
                return(Redirect($"/Lobby/Show/{lobby.LobbyId}"));
            }

            //TODO: Return error.
        }
示例#2
0
        public void Create_CallsRepositoryAdd()
        {
            // Assert that we hit the repository.
            LobbyRepository.DidNotReceive().Add(Arg.Any <Lobby>());
            MyWork.DidNotReceive().Complete();

            var viewModel = new CreateLobbyViewModel()
            {
                Description = "Description",
                Name        = "Name"
            };

            uut.Create(viewModel);

            // Assert that we hit the repository.
            LobbyRepository.Received(1).Add(Arg.Any <Lobby>());
            MyWork.Received(1).Complete();
        }
示例#3
0
        public void Create_InputFromViewModel_StoredInRepository()
        {
            // Create the viewmodel.
            var viewModel = new CreateLobbyViewModel()
            {
                Description = "Description",
                Name        = "Name"
            };

            // Setup storing retrieved calls.
            Lobby lobby = new Lobby();

            LobbyRepository.Add(Arg.Do <Lobby>(l => lobby = l));

            // Perform the action.
            uut.Create(viewModel);

            // Assert that the object passed to the repository, matches our data.
            Assert.That(lobby.Description, Is.EqualTo(viewModel.Description));
            Assert.That(lobby.Name, Is.EqualTo(viewModel.Name));
            // TODO: Extend.
        }
示例#4
0
 private void Initialize()
 {
     InitializeComponent();
     viewModel      = (CreateLobbyViewModel)base.DataContext;
     viewModel.View = this;
 }