| 39 | | |
| 40 | | |
| | 39 | |
| | 40 | public vPlatnosciEcard createPayment(int id, string nip, string fak_numer, decimal brutto, byte SystemKsiegowy) |
| | 41 | { |
| | 42 | |
| | 43 | vPlatnosciEcard platnosc = new vPlatnosciEcard(); |
| | 44 | platnosc.ID_faktury = id; |
| | 45 | platnosc.nip = nip; |
| | 46 | platnosc.Faktura_Numer = fak_numer; |
| | 47 | platnosc.Brutto = brutto; |
| | 48 | platnosc.SystemKsiegowyId = SystemKsiegowy; |
| | 49 | |
| | 50 | return platnosc; |
| | 51 | } |
| | 52 | public PlatnosciEcard createNewPayment(int ordernumber, bool status, DateTime data, int id_faktury) |
| | 53 | { |
| | 54 | PlatnosciEcard platnosc = new PlatnosciEcard(); |
| | 55 | platnosc.ORDERNUMBER = ordernumber; |
| | 56 | platnosc.Status = status; |
| | 57 | platnosc.Status_data = data; |
| | 58 | platnosc.IDFaktury = id_faktury; |
| | 59 | |
| | 60 | return platnosc; |
| | 61 | } |
| | 62 | public Payer createPayer(int id, string name, string surname) |
| | 63 | { |
| | 64 | Payer payer = new Payer(); |
| | 65 | payer.Id_faktury = id; |
| | 66 | payer.FirstName = name; |
| | 67 | payer.LastName = surname; |
| | 68 | |
| | 69 | return payer; |
| | 70 | } |
| | 71 | public ControllerContext createControllerContext(string UserIdentity) |
| | 72 | { |
| | 73 | |
| | 74 | var mock = new Mock<ControllerContext>(); |
| | 75 | mock.SetupGet(m => m.HttpContext.User.Identity.Name).Returns(UserIdentity); |
| | 76 | mock.SetupGet(m => m.HttpContext.Request.IsAuthenticated).Returns(true); |
| | 77 | |
| | 78 | return mock.Object; |
| | 79 | } |
| 126 | | public void AddPayment() |
| 127 | | { |
| 128 | | FakeDataContext fake = new FakeDataContext(); |
| 129 | | IRepository<vPlatnosciEcard> _rep = new Repository<vPlatnosciEcard>(fake); |
| 130 | | |
| 131 | | vPlatnosciEcard platnosc = new vPlatnosciEcard(); |
| 132 | | platnosc.ID_faktury = 13; |
| 133 | | platnosc.nip = "nipek"; |
| 134 | | _rep.Insert(platnosc); |
| 135 | | |
| 136 | | vPlatnosciEcard pl1 = new vPlatnosciEcard(); |
| 137 | | pl1.ID_faktury = 14; |
| 138 | | pl1.nip = "vv"; |
| | 150 | public void TestInsertMethodForPayment() |
| | 151 | { |
| | 152 | FakeDataContext fake = new FakeDataContext(); |
| | 153 | IRepository<vPlatnosciEcard> _rep = new Repository<vPlatnosciEcard>(fake); |
| | 154 | |
| | 155 | vPlatnosciEcard platnosc = createPayment(13, "nipek", "", 0, 0); |
| | 156 | _rep.Insert(platnosc); |
| | 157 | |
| | 158 | vPlatnosciEcard pl1 = createPayment(14, "vv", "", 0, 0); |
| 146 | | public void ShowPayment_BadNip() |
| 147 | | { |
| 148 | | FakeDataContext fake = new FakeDataContext(); |
| 149 | | IRepository<vPlatnosciEcard> _rep = new Repository<vPlatnosciEcard>(fake); |
| 150 | | |
| 151 | | vPlatnosciEcard platnosc = new vPlatnosciEcard(); |
| 152 | | platnosc.ID_faktury = 74828; |
| 153 | | platnosc.nip = "854956281"; |
| 154 | | platnosc.Faktura_Numer = "27/ASZ/2009"; |
| 155 | | _rep.Insert(platnosc); |
| 156 | | |
| 157 | | var builder = new TestControllerBuilder(); |
| 158 | | var controller = new PlatnoscController(fake); |
| 159 | | controller.setUserIdentity("122"); |
| 160 | | controller.setWeryfikacja("Niepoprawny nip"); |
| 161 | | builder.InitializeController(controller); |
| | 166 | public void ActionShowPayment_IncorrectUserIdentity_ReturnErrorView() |
| | 167 | { |
| | 168 | FakeDataContext fake = new FakeDataContext(); |
| | 169 | IRepository<vPlatnosciEcard> _rep = new Repository<vPlatnosciEcard>(fake); |
| | 170 | |
| | 171 | vPlatnosciEcard platnosc = createPayment(74828, "854956281", "27/ASZ/2009", 0, 0); |
| | 172 | _rep.Insert(platnosc); |
| | 173 | |
| | 174 | var controller = new PlatnoscController(fake); |
| | 175 | controller.ControllerContext = createControllerContext("1"); |
| | 176 | controller.setWeryfikacja("Niepoprawny nip"); |
| 166 | | Assert.That(error.error, Is.EqualTo("Niepoprawny nip")); |
| 167 | | |
| 168 | | } |
| 169 | | [Test] |
| 170 | | [Category("Unit")] |
| 171 | | public void ShowPayment_CorrectData() |
| 172 | | { |
| 173 | | FakeDataContext fake = new FakeDataContext(); |
| 174 | | IRepository<vPlatnosciEcard> _rep = new Repository<vPlatnosciEcard>(fake); |
| 175 | | |
| 176 | | vPlatnosciEcard platnosc = new vPlatnosciEcard(); |
| 177 | | platnosc.ID_faktury = 74828; |
| 178 | | platnosc.nip = "854956281"; |
| 179 | | platnosc.Faktura_Numer = "27/ASZ/2009"; |
| 180 | | platnosc.Brutto = 200; |
| 181 | | _rep.Insert(platnosc); |
| 182 | | |
| 183 | | var builder = new TestControllerBuilder(); |
| 184 | | var controller = new PlatnoscController(fake); |
| 185 | | controller.setUserIdentity("854956281"); |
| 186 | | builder.InitializeController(controller); |
| | 182 | Assert.That(error.error, Is.EqualTo("Niepoprawny nip")); |
| | 183 | Assert.That(result.ViewName, Is.EqualTo("Error1")); |
| | 184 | } |
| | 185 | [Test] |
| | 186 | [Category("Unit")] |
| | 187 | public void ActionShowPayment_PaymentNotFound_ReturnErrorView() |
| | 188 | { |
| | 189 | FakeDataContext fake = new FakeDataContext(); |
| | 190 | IRepository<vPlatnosciEcard> _rep = new Repository<vPlatnosciEcard>(fake); |
| | 191 | |
| | 192 | vPlatnosciEcard platnosc = createPayment(74828, "854956281", "27/ASZ/2009", 0,0); |
| | 193 | _rep.Insert(platnosc); |
| | 194 | |
| | 195 | var controller = new PlatnoscController(fake); |
| | 196 | |
| | 197 | controller.ControllerContext = createControllerContext("854956281"); |
| | 198 | controller.setBrakDanych("Platnosc o takim id nie istnieje"); |
| | 199 | |
| | 200 | var result = controller.Show("123", "pl") as ViewResult; |
| | 201 | var error = (ErrorViewData)result.ViewData.Model; |
| | 202 | |
| | 203 | Assert.That(error.error, Is.EqualTo("Platnosc o takim id nie istnieje")); |
| | 204 | Assert.That(result.ViewName, Is.EqualTo("Error1")); |
| | 205 | } |
| | 206 | [Test] |
| | 207 | [Category("Unit")] |
| | 208 | public void ActionShowPayment_PaymentIsPayed(){ |
| | 209 | //Tworzymy takie dane aby platnosc o danym id byla juz zaplacona |
| | 210 | FakeDataContext fake = new FakeDataContext(1); |
| | 211 | var controller = new PlatnoscController(fake); |
| | 212 | |
| | 213 | controller.ControllerContext = createControllerContext("nip"); |
| | 214 | controller.setZaplacono("Platnosc zostala uregulowana"); |
| | 215 | |
| | 216 | var result = controller.Show("128", "pl") as ViewResult; |
| | 217 | var error = (ErrorViewData)result.ViewData.Model; |
| | 218 | |
| | 219 | Assert.That(result.ViewName, Is.EqualTo("Error1")); |
| | 220 | Assert.That(error.error, Is.EqualTo("Platnosc zostala uregulowana")); |
| | 221 | } |
| | 222 | [Test] |
| | 223 | [Category("Unit")] |
| | 224 | public void ActionShowPayment_CorrectData_ReturnViewForPayment() |
| | 225 | { |
| | 226 | FakeDataContext fake = new FakeDataContext(); |
| | 227 | IRepository<vPlatnosciEcard> _rep = new Repository<vPlatnosciEcard>(fake); |
| | 228 | |
| | 229 | vPlatnosciEcard platnosc = createPayment(74828,"854956281","27/ASZ/2009",200,0); |
| | 230 | _rep.Insert(platnosc); |
| | 231 | |
| | 232 | var controller = new PlatnoscController(fake); |
| | 233 | controller.ControllerContext = createControllerContext("854956281"); |
| 192 | | Assert.That(view.vPlatnosciEcard.Faktura_Numer, Is.EqualTo("27/ASZ/2009")); |
| 193 | | |
| 194 | | } |
| 195 | | [Test] |
| 196 | | [Category("Unit")] |
| 197 | | public void PaymentIsNotValid() |
| 198 | | { |
| 199 | | FakeDataContext fake = new FakeDataContext(); |
| 200 | | IRepository<vPlatnosciEcard> _rep = new Repository<vPlatnosciEcard>(fake); |
| 201 | | |
| 202 | | vPlatnosciEcard platnosc = new vPlatnosciEcard(); |
| 203 | | platnosc.ID_faktury = 74828; |
| 204 | | platnosc.nip = "854956281"; |
| 205 | | platnosc.Faktura_Numer = "27/ASZ/2009"; |
| 206 | | platnosc.Brutto = 200; |
| 207 | | platnosc.SystemKsiegowyId = 2; |
| 208 | | _rep.Insert(platnosc); |
| 209 | | |
| 210 | | var builder = new TestControllerBuilder(); |
| 211 | | var controller = new PlatnoscController(fake); |
| 212 | | controller.setUserIdentity("854956281"); |
| 213 | | builder.InitializeController(controller); |
| 214 | | |
| 215 | | Payer payer = new Payer(); |
| 216 | | payer.Id_faktury = 74828; |
| 217 | | payer.LastName = "test"; //Nie wprowadzono imienia |
| 218 | | |
| | 240 | Assert.That(view.vPlatnosciEcard.Faktura_Numer, Is.EqualTo("27/ASZ/2009")); |
| | 241 | } |
| | 242 | [Test] |
| | 243 | [Category("Unit")] |
| | 244 | public void AfterPay_PaymentIsNotValid() |
| | 245 | { |
| | 246 | FakeDataContext fake = new FakeDataContext(); |
| | 247 | IRepository<vPlatnosciEcard> _rep = new Repository<vPlatnosciEcard>(fake); |
| | 248 | |
| | 249 | vPlatnosciEcard platnosc = createPayment(74828, "854956281", "27/ASZ/2009", 200, 2); |
| | 250 | _rep.Insert(platnosc); |
| | 251 | |
| | 252 | var controller = new PlatnoscController(fake); |
| | 253 | controller.ControllerContext = createControllerContext("854956281"); |
| | 254 | |
| | 255 | Payer payer = createPayer(74828, "", "test"); //Brak imienia |
| 224 | | public void PaymentIsValid() |
| 225 | | { |
| 226 | | FakeDataContext fake = new FakeDataContext(); |
| 227 | | IRepository<vPlatnosciEcard> _rep = new Repository<vPlatnosciEcard>(fake); |
| 228 | | |
| 229 | | vPlatnosciEcard platnosc = new vPlatnosciEcard(); |
| 230 | | platnosc.ID_faktury = 74828; |
| 231 | | platnosc.nip = "854956281"; |
| 232 | | platnosc.Faktura_Numer = "27/ASZ/2009"; |
| 233 | | platnosc.Brutto = 200; |
| 234 | | platnosc.SystemKsiegowyId = 2; |
| 235 | | _rep.Insert(platnosc); |
| 236 | | |
| 237 | | var builder = new TestControllerBuilder(); |
| 238 | | var controller = new PlatnoscController(fake); |
| 239 | | controller.setUserIdentity("854956281"); |
| 240 | | builder.InitializeController(controller); |
| 241 | | |
| 242 | | Payer payer = new Payer(); |
| 243 | | payer.Id_faktury = 74828; |
| 244 | | payer.LastName = "test"; |
| 245 | | payer.FirstName = "test"; |
| 246 | | |
| | 262 | public void AfterPay_PaymentIsValid() |
| | 263 | { |
| | 264 | FakeDataContext fake = new FakeDataContext(); |
| | 265 | IRepository<vPlatnosciEcard> _rep = new Repository<vPlatnosciEcard>(fake); |
| | 266 | |
| | 267 | vPlatnosciEcard platnosc = createPayment(74828, "854956281", "27/ASZ/2009", 200, 2); |
| | 268 | _rep.Insert(platnosc); |
| | 269 | |
| | 270 | var controller = new PlatnoscController(fake); |
| | 271 | controller.ControllerContext = createControllerContext("854956281"); |
| | 272 | |
| | 273 | Payer payer = createPayer(74828, "test", "test"); |
| 249 | | } |
| 250 | | [Test] |
| 251 | | [Category("Unit")] |
| 252 | | public void ShowPayment_BadId() |
| 253 | | { |
| 254 | | FakeDataContext fake = new FakeDataContext(); |
| 255 | | IRepository<vPlatnosciEcard> _rep = new Repository<vPlatnosciEcard>(fake); |
| 256 | | |
| 257 | | vPlatnosciEcard platnosc = new vPlatnosciEcard(); |
| 258 | | platnosc.ID_faktury = 74828; |
| 259 | | platnosc.nip = "854956281"; |
| 260 | | platnosc.Faktura_Numer = "27/ASZ/2009"; |
| 261 | | _rep.Insert(platnosc); |
| 262 | | |
| 263 | | var builder = new TestControllerBuilder(); |
| 264 | | var controller = new PlatnoscController(fake); |
| 265 | | controller.setUserIdentity("1"); |
| 266 | | controller.setWeryfikacja("Nie ma takiej platnosci."); |
| 267 | | builder.InitializeController(controller); |
| 268 | | |
| 269 | | var result = controller.Show("1", "pl") as ViewResult; |
| 270 | | var error = (ErrorViewData)result.ViewData.Model; |
| 271 | | |
| 272 | | Assert.That(error.error, Is.EqualTo("Nie ma takiej platnosci.")); |
| 273 | | |
| 274 | | } |
| | 277 | } |