Ejemplo n.º 1
0
        public void Update_ExistingClient_Valid()
        {
            var clientsInMemory = new List <Client> {
                GetClient()
            };

            var mockDbSet = new Mock <DbSet <Client> >();

            PrepareQueryableMock(clientsInMemory, mockDbSet);

            //mocking add method
            mockDbSet.Setup(m => m.Add(It.IsAny <Client>()))
            .Callback <Client>(clientsInMemory.Add);

            var dbContext = new ClientsApiDbContext {
                Clients = mockDbSet.Object
            };
            var repo = new ClientsRepository(dbContext);

            var client = GetClient();

            client.City = "Belo Horizonte";
            repo.Update(client);

            Assert.IsTrue(clientsInMemory.Count == 1);
            Assert.AreEqual("Belo Horizonte", clientsInMemory[0].City);
        }
Ejemplo n.º 2
0
        private void UpdateTest()
        {
            const string newClientName = "New name";

            using (var context = new Context())
            {
                var clientsRepository = new ClientsRepository(context);
                context.Database.Log = (message) => Debug.WriteLine(message);

                _clientDataMock.Client.ClientName = newClientName;

                clientsRepository.Update(_clientDataMock.Client);
            }

            using (var context = new Context())
            {
                var clientsRepository = new ClientsRepository(context);
                context.Database.Log = (message) => Debug.WriteLine(message);

                var downloadedClient = clientsRepository.Get(_clientDataMock.ClientId);

                Assert.AreEqual(newClientName, downloadedClient.ClientName);
                Assert.True(downloadedClient.Projects.Count > 0, "UpdateTest does not return related projects");
                Assert.True(downloadedClient.Projects.All(p => p.Auditors.Count > 0), "UpdateTest does not return related auditors");
            }
        }
Ejemplo n.º 3
0
        private void UpdateClientBtn_Click(object sender, EventArgs e)
        {
            Client client = (Client)ClientsDataGrid.CurrentRow.DataBoundItem;

            ClientEditForm form   = new ClientEditForm(client);
            var            result = form.ShowDialog();

            if (result == DialogResult.OK)
            {
                _clientsRepository.Update(form.Client);
                FillGrids();
            }
        }
Ejemplo n.º 4
0
        public async Task Update_NoUpdatingEntity_InsertsData()
        {
            // Arrange
            var clientEntity = new ClientEntity(Guid.NewGuid(), "Client 1");

            var sut = new ClientsRepository(this.mongoCollection);

            // Act
            await sut.Update(clientEntity);

            var actual = await this.mongoCollection
                         .Find(q => q.Id == clientEntity.Id)
                         .SingleAsync();

            // Assert
            actual.Should().BeEquivalentTo(clientEntity);
        }
Ejemplo n.º 5
0
        public ActionResult Edit(ClientEditViewModel viewModel)
        {
            // ValidateEmployee(viewModel.Client);

            if (ModelState.IsValid)
            {
                var client = viewModel.Client;

                _clientRepo.Update(client);

                TempData["Message"] = "Client was successfully updated!";

                return(RedirectToAction("Detail", new { id = client.Id }));
            }

            return(View(viewModel));
        }
Ejemplo n.º 6
0
        public void Update_NewClient_Valid()
        {
            var clientsInMemory = new List <Client>();
            var client          = GetClient();

            var mockDbSet = new Mock <DbSet <Client> >();

            PrepareQueryableMock(clientsInMemory, mockDbSet);

            //mocking add method
            mockDbSet.Setup(m => m.Add(It.IsAny <Client>()))
            .Callback <Client>(clientsInMemory.Add);

            var dbContext = new ClientsApiDbContext {
                Clients = mockDbSet.Object
            };
            var repo = new ClientsRepository(dbContext);

            repo.Update(client);

            Assert.IsTrue(clientsInMemory.Contains(client));
        }