/// <summary> /// Creates a user in DBV /// </summary> /// <param name="userEntity"></param> /// <returns></returns> public Guid CreateUser(CustomerAPI userEntity) { using (var scope = new TransactionScope()) { var userHMIS = new CustomerAPI { EmailAddress = userEntity.EmailAddress, UserAgent = userEntity.UserAgent, // password = EncryptText("wgt_hmis", userEntity.password), FirstName = userEntity.FirstName, LastName = userEntity.LastName, Address1 = userEntity.Address1, Address2 = userEntity.Address2, City = userEntity.City, CreatedOn = DateTime.Now, // CreatedBy = "To be done", Postcode = userEntity.Postcode, Password = userEntity.Password, AuthData = userEntity.AuthData }; _dynamoDataService.Store(userHMIS); // _unitOfWork.Save(); scope.Complete(); return userHMIS.Id; } }
/// <summary> /// Returns auth token for the validated user. /// </summary> /// <param name="userId"></param> /// <returns></returns> private HttpResponseMessage GetAuthToken(BasicAuthenticationIdentity userId) { LoginResponseObject obj = new LoginResponseObject(); CustomerAPI objCus = new CustomerAPI(); objCus.EmailAddress = userId.UserName; objCus.UserType = userId.UserType; var token = _tokenServices.GenerateToken(objCus); obj.Authorized = "Authorized:"; obj.access_token = token; obj.userName = userId.UserName.ToString(); //obj.expiration = token.ExpiresOn.ToLongDateString(); obj.userData.email = userId.UserId.ToString(); // obj.userData.id = userId.ToString(); var response = Request.CreateResponse(HttpStatusCode.OK, obj); response.Headers.Add("Token", token.AuthToken); response.Headers.Add("UserID", userId.UserId.ToString()); // response.Headers.Add("TokenExpiry", ConfigurationManager.AppSettings["AuthTokenExpiry"]); response.Headers.Add("Access-Control-Expose-Headers", "Token,TokenExpiry"); response.Content.Headers.Add("access_token", token.AuthToken); //response.Content.Headers.Add("userName", userId.ToString()); var session = HttpContext.Current.Session; //if(session!=null) //{ // if(session["AuthUser"]==null) // { // session["AuthUser"] = token; // } //} return(response); }
private static bool AddCustomerNumberOne(Mock <ICustomerManager> customermanagerMock) { var customer = new CustomerAPI(customermanagerMock.Object); var successfull = customer.AddCustomer("2009-01-23", 1); return(successfull); }
public void TestRemoveCustomerOweMoney() { var customerManagerMock = new Mock <ICustomerManager>(); customerManagerMock.Setup(m => m.GetCustomer(It.IsAny <int>())) .Returns(new Customer { CustomerID = 1, Bills = new List <Bill> { new Bill { } } }); customerManagerMock.Setup(m => m.RemoveCustomer(It.IsAny <Customer>())); var CustomerAPI = new CustomerAPI(customerManagerMock.Object, null, null); var successfull = CustomerAPI.RemoveCustomer(1); Assert.AreEqual(CustomerErrorCodes.CustomerStillOwesMoney, successfull); customerManagerMock.Verify(m => m.RemoveCustomer(It.IsAny <Customer>()), Times.Never); }
//ADD CUSTOMER: private AddCustomerStatusCodes AddCustomerNumberOne(Mock <ICustomerManager> customerManagerMock) { var customerAPI = new CustomerAPI(customerManagerMock.Object, null); var successfull = customerAPI.AddCustomer(000001, "Fanny Uhr", "1996-07-22", "Peppargatan 13", null); return(successfull); }
private CustomerStatusCodes AddCustomerNumberOne(Mock <ICustomerManager> customerManagerMock) { var customerAPI = new CustomerAPI(customerManagerMock.Object); var successfull = customerAPI.AddCustomer("Erika Axelsson", "Restalundsvägen 2", "1996-4-4", 0, null); return(successfull); }
private static AddCustomerErrorCodes AddCustomer(Mock <ICustomerManager> customerManagerMock) { var customerAPI = new CustomerAPI(customerManagerMock.Object); var successfull = customerAPI.AddCustomer(1, "9103273877"); return(successfull); }
public void AddCustomerNoSuchBirthDate() { var customerManagerMock = new Mock <ICustomerManager>(); var customerApi = new CustomerAPI(customerManagerMock.Object, null); var result = customerApi.AddCustomer(000002, "Harald Hansson", "12345", "Wilhelmgatan 3", null); Assert.AreEqual(AddCustomerStatusCodes.InvalidBirthDate, result); }
public void TestValitadeDateOk() { var customerManagerMock = new Mock <ICustomerManager>(); var customerAPI = new CustomerAPI(customerManagerMock.Object); bool result = customerAPI.CheckValidDate("1996-4-4"); Assert.IsTrue(result); }
public void TestValidateBirthDateOk() { var customerManagerMock = new Mock <ICustomerManager>(); var customerApi = new CustomerAPI(customerManagerMock.Object, null); var result = customerApi.ValidateBirthDate("1996-07-22"); Assert.IsTrue(result); }
public void TestValidateDateFail() { var customerManagerMock = new Mock <ICustomerManager>(); var customerAPI = new CustomerAPI(customerManagerMock.Object); bool result = customerAPI.CheckValidDate("4-4-1996"); Assert.IsFalse(result); }
public void TestGetAgeFail() { var customerManagerMock = new Mock <ICustomerManager>(); var customerApi = new CustomerAPI(customerManagerMock.Object, null); var result = customerApi.GetAge("1996-07-22"); Assert.AreNotEqual(32, result); }
public void TestValidateBirthDateFailFormat() { var customerManagerMock = new Mock <ICustomerManager>(); var customerApi = new CustomerAPI(customerManagerMock.Object, null); var result = customerApi.ValidateBirthDate("1996/07/22"); Assert.IsFalse(result); }
public void TestValidateBirthDateFailLetters() { var customerManagerMock = new Mock <ICustomerManager>(); var customerApi = new CustomerAPI(customerManagerMock.Object, null); var result = customerApi.ValidateBirthDate("Hejhopp"); Assert.IsFalse(result); }
public void TestGetAgeFail() { var customerManagerMock = new Mock <ICustomerManager>(); var customerAPI = new CustomerAPI(customerManagerMock.Object); var result = customerAPI.GetAge("1996-4-4"); Assert.AreNotEqual(24, result); }
public void TestAddCustomerIDNumberNotValid() { var customerManagerMock = new Mock <ICustomerManager>(); var customerAPI = new CustomerAPI(customerManagerMock.Object); var successfull = customerAPI.AddCustomer(1, "9103273872"); Assert.AreEqual(AddCustomerErrorCodes.IDNumberNotValid, successfull); customerManagerMock.Verify(m => m.AddCustomer(It.IsAny <int>(), It.IsAny <string>()), Times.Never()); }
public void CancelCustomerNoSuchCustomer() { var customerManagerMock = SetupMock((Customer)null); var borrowManagerMock = SetupMock(new List <Borrow>()); var customerAPI = new CustomerAPI(customerManagerMock.Object, borrowManagerMock.Object); var result = customerAPI.CancelCustomer(000001); Assert.AreEqual(CancelCustomerStatusCodes.NoSuchCustomer, result); customerManagerMock.Verify(m => m.CancelCustomer(It.IsAny <int>()), Times.Never); }
/// <summary> /// Method Updates and existing item in the table : Working /// </summary> /// <typeparam name="T"></typeparam> /// <param name="item"></param> public void UpdateCustomerAuthItem(CustomerAPI item) { var savedItem = DbContext.Load <CustomerAPI>(item); savedItem.AuthData = item.AuthData; if (savedItem == null) { throw new AmazonDynamoDBException("The item does not exist in the Table"); } DbContext.Save(savedItem); }
private AddCustomerStatusCodes AddMinorCustomerNumberOne(Mock <ICustomerManager> customerManagerMock) { var guardian = (new Customer { CustomerID = 1, BirthDate = "1973-07-14" }); var customerAPI = new CustomerAPI(customerManagerMock.Object, null); var successfull = customerAPI.AddCustomer(000008, "Pontus Andersson", "2008-02-16", "Linfrögatan 22", guardian); return(successfull); }
public void TestAddCustomer() { var customerManagerMock = new Mock <ICustomerManager>(); customerManagerMock.Setup(m => m.AddCustomer(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <DateTime>(), It.IsAny <Customer>())); var CustomerAPI = new CustomerAPI(customerManagerMock.Object, null, null); var successfull = CustomerAPI.AddCustomer("Anna", "Fiskvägen 10", "10122000"); Assert.AreEqual(CustomerErrorCodes.ok, successfull); customerManagerMock.Verify(m => m.AddCustomer(It.Is <string>(s => s == "Anna"), It.Is <string>(a => a == "Fiskvägen 10"), It.Is <DateTime>(d => d.Month == 12), It.Is <Customer>(c => c == null)), Times.Once); }
public void TestAddCustomerUnderAge() { var customerManagerMock = new Mock <ICustomerManager>(); customerManagerMock.Setup(m => m.AddCustomer(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <DateTime>(), It.IsAny <Customer>())); var CustomerAPI = new CustomerAPI(customerManagerMock.Object, null, null); var successfull = CustomerAPI.AddCustomer("Anna", "Fiskvägen 10", "01012019"); Assert.AreEqual(CustomerErrorCodes.CustomerToYoungMustHaveParent, successfull); customerManagerMock.Verify(m => m.AddCustomer(It.Is <string>(s => s == "Anna"), It.Is <string>(a => a == "Fiskvägen 10"), It.IsAny <DateTime>(), It.Is <Customer>(c => c == null)), Times.Never); }
public void TestAddCustomerWrongDate() { var customerManagerMock = new Mock <ICustomerManager>(); customerManagerMock.Setup(m => m.AddCustomer(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <DateTime>(), It.IsAny <Customer>())); var CustomerAPI = new CustomerAPI(customerManagerMock.Object, null, null); var successfull = CustomerAPI.AddCustomer("Anna", "Fiskvägen 10", "11132019"); Assert.AreEqual(CustomerErrorCodes.CustomerDateOfBirthIsIncorrect, successfull); customerManagerMock.Verify(m => m.AddCustomer(It.Is <string>(s => s == "Anna"), It.Is <string>(a => a == "Fiskvägen 10"), It.IsAny <DateTime>(), It.Is <Customer>(c => c == null)), Times.Never); }
public void TestRemoveNonExistingCustomer() { var customerManagerMock = new Mock <ICustomerManager>(); customerManagerMock.Setup(m => m.GetCustomerByCustomerName(It.IsAny <string>())) .Returns((Customer)null); var customerAPI = new CustomerAPI(customerManagerMock.Object); var successfull = customerAPI.RemoveCustomer("Ola Lola"); Assert.AreEqual(CustomerStatusCodes.NoSuchCustomer, successfull); customerManagerMock.Verify(m => m.RemoveCustomer(It.IsAny <int>()), Times.Never); }
private void SavePerson_Click(object sender, EventArgs e) { Person person = new Person(); person.id = int.Parse(Id.Text); person.name = fname.Text; person.family = lname.Text; person.age = DateTime.Parse(age.Text); person.city = city.Text; CustomerAPI customerAPI = new CustomerAPI(); customerAPI.SaveCustomer(person); }
/// <summary> /// Not In Use : Test Method -- Testt Data with Hard code value /// </summary> public void UpdateMultipleAttributes(CustomerAPI value) { var request = new UpdateItemRequest { Key = new Dictionary <string, AttributeValue>() { { "EmailAddress", new AttributeValue { S = "*****@*****.**" } }, { "UserType", new AttributeValue { S = "Customer" } } }, // Perform the following updates: // 1) Add two new authors to the list // 1) Set a new attribute // 2) Remove the ISBN attribute ExpressionAttributeNames = new Dictionary <string, string>() { { "#A", "AuthData.AuthToken" }, { "#NA", "NewAttribute" }//, //{"#I","Dnc"} }, ExpressionAttributeValues = new Dictionary <string, AttributeValue>() { { ":auth", new AttributeValue { S = "Test Token" } }, { ":new", new AttributeValue { S = "New Value" } } }, // UpdateExpression = "ADD #A :auth SET #NA = :new REMOVE #I", UpdateExpression = "ADD #A :auth SET #NA = :new ", TableName = "CustomerAPI", ReturnValues = "ALL_NEW" // Give me all attributes of the updated item. }; var response = DynamoClient.UpdateItem(request); // Check the response. var attributeList = response.Attributes; }
public void TestRemoveCustomerNoSuchCustomer() { var customerManagerMock = new Mock <ICustomerManager>(); customerManagerMock.Setup(m => m.GetCustomer(It.IsAny <int>())) .Returns <Customer>(null); customerManagerMock.Setup(m => m.RemoveCustomer(It.IsAny <Customer>())); var CustomerAPI = new CustomerAPI(customerManagerMock.Object, null, null); var successfull = CustomerAPI.RemoveCustomer(1); Assert.AreEqual(CustomerErrorCodes.NoSuchCustomer, successfull); customerManagerMock.Verify(m => m.RemoveCustomer(It.IsAny <Customer>()), Times.Never); }
public void CancelCustomerHasDebt() { var customerManagerMock = SetupMock(new Customer { CustomerNumber = 000001, Debt = 30, IsGuardian = false }); var borrowManagerMock = SetupMock(new List <Borrow>()); var customerAPI = new CustomerAPI(customerManagerMock.Object, borrowManagerMock.Object); var result = customerAPI.CancelCustomer(000001); Assert.AreEqual(CancelCustomerStatusCodes.CustomerHasUnpaidDebt, result); customerManagerMock.Verify(m => m.CancelCustomer(It.IsAny <int>()), Times.Never); }
public void TestRemoveUnActiveCustomer() { var customerManagerMock = new Mock <ICustomerManager>(); customerManagerMock.Setup(m => m.GetCustomerByCustomerName(It.IsAny <string>())) .Returns(new Customer { CustomerName = "Britta Bo", Loan = new List <Loan>() }); var customerAPI = new CustomerAPI(customerManagerMock.Object); var successfull = customerAPI.RemoveCustomer("Britta Bo"); Assert.AreEqual(CustomerStatusCodes.Ok, successfull); customerManagerMock.Verify(m => m.RemoveCustomer(It.IsAny <int>()), Times.Once); }
public void TestReminderList() { var customerManagerMock = new Mock <ICustomerManager>(); customerManagerMock.Setup(m => m.GetAllCustomers()) .Returns( new List <Customer> { new Customer { Name = "Adam", Address = "Örebro", Borrows = new List <Borrow> { new Borrow { DateOfBorrow = new DateTime(2018, 10, 10), Book = new Book { } } } }, { new Customer { Name = "Lars", Address = "Kumla", Borrows = new List <Borrow> { new Borrow { DateOfBorrow = new DateTime(2019, 10, 10), Book = new Book { } }, new Borrow { DateOfBorrow = new DateTime(2018, 10, 10), Book = new Book { } } } } } } ); var CustomerAPI = new CustomerAPI(customerManagerMock.Object, null, null); var reminderList = CustomerAPI.getReminderList(); Assert.AreEqual(reminderList.Count, 2); }
public void TestRemoveCustomer() { var customerManagerMock = new Mock <ICustomerManager>(); customerManagerMock.Setup(m => m.GetCustomerByCustomerNumber(It.IsAny <int>())) .Returns(new Customer { CustomerNumber = 1, Book = new List <Book>(), Debt = new List <Debt>() }); var libraryAPI = new CustomerAPI(customerManagerMock.Object); var successfull = libraryAPI.RemoveCustomer(4); Assert.AreEqual(RemoveCustomerErrorCodes.Ok, successfull); customerManagerMock.Verify(m => m.RemoveCustomer(It.IsAny <int>()), Times.Once); }