Skip to content

Commit

Permalink
Improvements about the update of a user
Browse files Browse the repository at this point in the history
  • Loading branch information
joaquinlamela committed Nov 26, 2020
1 parent d48c147 commit acf5003
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 5 deletions.
5 changes: 5 additions & 0 deletions Uru_NaturalBooking/BusinessLogic/UserManagement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ public User UpdateUser(Guid userToModifyId, User aUser)
try
{
User userDb = GetUser(userToModifyId);
VerifyIfUserExist(aUser);
userDb.UpdateAttributes(aUser);
userDb.VerifyFormat();
userRepository.Update(userDb);
Expand All @@ -171,6 +172,10 @@ public User UpdateUser(Guid userToModifyId, User aUser)
{
throw new ClientBusinessLogicException(e.Message);
}
catch (DomainBusinessLogicException e)
{
throw new DomainBusinessLogicException(e.Message);
}
catch (ServerException e)
{
throw new ServerBusinessLogicException("No se puede actualizar el usuario.", e);
Expand Down
26 changes: 26 additions & 0 deletions Uru_NaturalBooking/BusinessLogicTest/UserTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -592,13 +592,36 @@ public void UpdateValidUser()
user.Name = "Gonzalo";
var userRepositoryMock = new Mock<IUserRepository>(MockBehavior.Strict);
userRepositoryMock.Setup(m => m.Get(It.IsAny<Guid>())).Returns(user);
userRepositoryMock.Setup(m => m.GetUserByEmail(It.IsAny<string>())).Returns(value: null);
userRepositoryMock.Setup(m => m.Update(It.IsAny<User>()));
var userLogic = new UserManagement(userRepositoryMock.Object);
var result = userLogic.UpdateUser(user.Id, user);
userRepositoryMock.VerifyAll();
Assert.AreEqual("Gonzalo", user.Name);
}

[TestMethod]
[ExpectedException(typeof(DomainBusinessLogicException))]
public void TryToUpdateUserWithRepeatedMailTest()
{
User user = new User()
{
Id = Guid.NewGuid(),
Name = "Martin",
LastName = "Gutman",
UserName = "colo20",
Mail = "[email protected]",
Password = "martin1234"
};
user.Name = "Gonzalo";
var userRepositoryMock = new Mock<IUserRepository>(MockBehavior.Strict);
userRepositoryMock.Setup(m => m.Get(It.IsAny<Guid>())).Returns(user);
userRepositoryMock.Setup(m => m.GetUserByEmail(It.IsAny<string>())).Returns(user);
userRepositoryMock.Setup(m => m.Update(It.IsAny<User>()));
var userLogic = new UserManagement(userRepositoryMock.Object);
var result = userLogic.UpdateUser(user.Id, user);
}

[TestMethod]
[ExpectedException(typeof(ClientBusinessLogicException))]
public void UpdateNotExistUser()
Expand All @@ -616,6 +639,7 @@ public void UpdateNotExistUser()
user.Name = "Gonzalo";
var userRepositoryMock = new Mock<IUserRepository>(MockBehavior.Strict);
userRepositoryMock.Setup(m => m.Get(It.IsAny<Guid>())).Throws(new ClientException());
userRepositoryMock.Setup(m => m.GetUserByEmail(It.IsAny<string>())).Returns(value: null);
var userLogic = new UserManagement(userRepositoryMock.Object);
var result = userLogic.UpdateUser(user.Id, user);
}
Expand All @@ -638,6 +662,7 @@ public void UpdateInvalidUserWithEmptyName()
user.Name = "";
var userRepositoryMock = new Mock<IUserRepository>(MockBehavior.Strict);
userRepositoryMock.Setup(m => m.Get(It.IsAny<Guid>())).Returns(user);
userRepositoryMock.Setup(m => m.GetUserByEmail(It.IsAny<string>())).Returns(value: null);
var userLogic = new UserManagement(userRepositoryMock.Object);
var result = userLogic.UpdateUser(user.Id, user);
}
Expand All @@ -659,6 +684,7 @@ public void UpdateUserInvalidDataBaseError()
user.Name = "Gonzalo";
var userRepositoryMock = new Mock<IUserRepository>(MockBehavior.Strict);
userRepositoryMock.Setup(m => m.Get(It.IsAny<Guid>())).Returns(user);
userRepositoryMock.Setup(m => m.GetUserByEmail(It.IsAny<string>())).Returns(value: null);
userRepositoryMock.Setup(m => m.Update(It.IsAny<User>())).Throws(new ServerException());
var userLogic = new UserManagement(userRepositoryMock.Object);
var result = userLogic.UpdateUser(user.Id, user);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using Microsoft.EntityFrameworkCore.Migrations;
using System.Diagnostics.CodeAnalysis;

namespace DataAccess.Migrations
{
[ExcludeFromCodeCoverage]
public partial class ObligatorioMigrationV123_11_2020 : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using Microsoft.EntityFrameworkCore.Migrations;
using System.Diagnostics.CodeAnalysis;

namespace DataAccess.Migrations
{
[ExcludeFromCodeCoverage]
public partial class ObligatorioMigrationV223_11_2020 : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using Microsoft.EntityFrameworkCore.Migrations;
using System.Diagnostics.CodeAnalysis;

namespace DataAccess.Migrations
{
[ExcludeFromCodeCoverage]
public partial class ObligatorioMigrationV323_11_2020 : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// <auto-generated />
using System;
using System.Diagnostics.CodeAnalysis;
using DataAccess;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
Expand All @@ -8,6 +9,7 @@

namespace DataAccess.Migrations
{
[ExcludeFromCodeCoverage]
[DbContext(typeof(ContextObl))]
partial class ContextOblModelSnapshot : ModelSnapshot
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[{
"name": "Hotel Enjoy Conrad",
"description": "Un lugar magico donde podes vivir.",
"name": "Sol y Luna Hotel",
"description": "El Sol y Luna Home & Spa ofrece alojamiento independiente con WiFi gratis en Punta del Este, a 300 metros de las playas Brava y Mansa.",
"quantityOfStars": 5,
"address": "Playa Mansa parada 21",
"images": ["Desktop\\conrad.jpg"],
"address": "Av. Chiverta esquina Arazatí, Aidy Grill,",
"images": ["https://cf.bstatic.com/xdata/images/hotel/max1280x900/40311205.webp?k=2d889779bbf27e507231b75672c9463553f63e57d5565378bdfb9895a88d83f4&o="],
"pricePerNight": 200.0,
"isAvailable": true,
"touristSpot": {
"id": "7cb8a7ab-8511-473f-803f-6b39118e79c1",
"id": "2E792C77-5DAD-43B8-88F3-FE0A26D21F16",
"name": "Punta del Este",
"description": "La naturaleza abunda",
"regionId": "fc775bb9-8cc8-4fdc-bca6-16e06bcd322b",
Expand Down

0 comments on commit acf5003

Please sign in to comment.