public async void Validate_User_Create_AND_Retrieve_Single_User() { var repo = getRepo(); // Test creating the User User resp = await repo.CreateUser(HelperData.User(), HelperData.userImageDTOWithoutData()); Assert.True(resp.Id > 0); // Test retrieving the created User User retrieve = await repo.GetSingle(resp.Id); Assert.True(retrieve.Id > 0); // Clean up by calling Delete const string sp = "DeleteUser"; DynamicParameters param = new DynamicParameters(); param.Add("@UserId", retrieve.Id); using (IDbConnection db = fixture.Db) { await db.ExecuteAsync(sp, param, commandType : CommandType.StoredProcedure); } }
public void isInterests_Optional() { var validUser = HelperData.User(); var validUserMissing = HelperData.User(); validUserMissing.Interests = null; Assert.True(HelperFunctions.Validate(validUser)); Assert.True(HelperFunctions.Validate(validUserMissing)); }
public void areUserClass_Property_Types_Standard() { var user = HelperData.User(); Assert.IsType <int>(user.Id); Assert.IsType <string>(user.FirstName); Assert.IsType <string>(user.LastName); Assert.IsType <DateTime>(user.Birthday); Assert.IsType <string>(user.Interests); Assert.IsType <Address>(user.Address); }
public void isInterests_Restricted_In_Length() { var validUser = HelperData.User(); var invalidUserShort = HelperData.User(); var invalidUserLong = HelperData.User(); invalidUserShort.Interests = new string('*', 2); invalidUserLong.Interests = new string('*', 251); Assert.True(HelperFunctions.Validate(validUser)); Assert.False(HelperFunctions.Validate(invalidUserShort)); Assert.False(HelperFunctions.Validate(invalidUserLong)); }
public void isLast_Restricted_In_Length_And_Required() { var validUser = HelperData.User(); var invalidUserShort = HelperData.User(); var invalidUserLong = HelperData.User(); var invalidUserMissing = HelperData.User(); invalidUserShort.LastName = ""; invalidUserLong.LastName = new string('*', 51); invalidUserMissing.LastName = null; Assert.True(HelperFunctions.Validate(validUser)); Assert.False(HelperFunctions.Validate(invalidUserShort)); Assert.False(HelperFunctions.Validate(invalidUserLong)); Assert.False(HelperFunctions.Validate(invalidUserMissing)); }
public async void Check_Address_Validation_On_Create() { var mockrepo = new Mock <IUserRepository>(); mockrepo.Setup(repo => repo.CreateUser(It.IsAny <User>(), It.IsAny <UserImageDTO>())) .ReturnsAsync(HelperData.User()); //Change the FirstName to an INVALID state on the Mapper Response var mapperMock = new Mock <IMapper>(); mapperMock.Setup(m => m.Map <UserDTO, User>(It.IsAny <UserDTO>())) .Returns(HelperData.User(City: "")); mapperMock.Setup(m => m.Map <User, UserDTO>(It.IsAny <User>())) .Returns(HelperData.UserDTO()); var usersrv = new UserService(mockrepo.Object, mapperMock.Object); //Checks model validation before creation await Assert.ThrowsAsync <InvalidOperationException>(async() => await usersrv.CreateUser(HelperData.UserDTO())); }