Zbiór zmian 872 dla trunk

Pokaż
Ignoruj:
Data:
2009-11-10 16:01:21 (16 years ago)
Autor:
alina
Opis:

re #215

Lokalizacja:
trunk/eCard/eCardMVC
Pliki:
4 dodane
4 zmodyfikowane

Legenda:

Bez zmian
Dodane
Usunięte
  • trunk/eCard/eCardMVC/Platnosci.Core/Linq/Repository.cs

    r870 r872  
    1717    public class Repository<T> : IRepository<T> where T : class, IIdentifiable 
    1818    { 
    19        // private readonly PlatnosciDataContext _dataContext = new PlatnosciDataContext(); 
    20         //private PlatnosciDataContext _dataContext = new PlatnosciDataContext(); 
    2119        protected readonly IDataContext _dataContext; 
    2220 
  • trunk/eCard/eCardMVC/Platnosci.Tests/Platnosci.Tests.csproj

    r871 r872  
    3232  </PropertyGroup> 
    3333  <ItemGroup> 
     34    <Reference Include="Moq, Version=4.0.812.4, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL"> 
     35      <SpecificVersion>False</SpecificVersion> 
     36      <HintPath>..\..\..\..\Documents and Settings\Administrator\Pulpit\Moq.4.0.812.4-bin\Moq.dll</HintPath> 
     37    </Reference> 
    3438    <Reference Include="MvcContrib, Version=1.5.996.0, Culture=neutral, processorArchitecture=MSIL"> 
    3539      <SpecificVersion>False</SpecificVersion> 
     
    5458    <Reference Include="System" /> 
    5559    <Reference Include="System.Core"> 
     60      <RequiredTargetFramework>3.5</RequiredTargetFramework> 
     61    </Reference> 
     62    <Reference Include="System.Web.Abstractions"> 
    5663      <RequiredTargetFramework>3.5</RequiredTargetFramework> 
    5764    </Reference> 
  • trunk/eCard/eCardMVC/Platnosci.Tests/Web/PlatnosciControllerTests.cs

    r871 r872  
    1414using System.Threading; 
    1515using Platnosci.Models; 
    16 using Rhino.Mocks; 
     16using Moq; 
    1717 
    1818namespace Platnosci.Tests.Web 
     
    3737         } 
    3838        */ 
    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        } 
    4180        [Test] 
    4281        [Category("Unit")] 
     
    65104            FakeDataContext fake = new FakeDataContext(); 
    66105            IRepository<PlatnosciEcard> _rep = new Repository<PlatnosciEcard>(fake); 
    67               
     106 
    68107            DateTime data = DateTime.Now; 
    69  
    70             PlatnosciEcard platnosc = new PlatnosciEcard(); 
    71             platnosc.ORDERNUMBER = 1; 
    72             platnosc.Status = true; 
    73             platnosc.Status_data = data; 
    74             _rep.Insert(platnosc); 
    75  
    76             var builder = new TestControllerBuilder(); 
    77             var controller = new PlatnoscController(fake); 
    78             builder.InitializeController(controller);          
    79  
     108            PlatnosciEcard platnosc = createNewPayment(1, true, data, 1); 
     109            _rep.Insert(platnosc); 
     110 
     111            var controller = new PlatnoscController(fake);  
    80112            controller.UpdateStatus(1, "000");   //000 - płatność poprawna 
    81113 
     
    93125            DateTime data = DateTime.Now; 
    94126 
    95             PlatnosciEcard platnosc = new PlatnosciEcard(); 
    96             platnosc.ORDERNUMBER = 1; 
    97             platnosc.Status = true; 
    98             platnosc.Status_data = data; 
    99             _rep.Insert(platnosc); 
    100  
    101             var builder = new TestControllerBuilder(); 
    102             var controller = new PlatnoscController(fake); 
    103             builder.InitializeController(controller); 
    104  
     127            PlatnosciEcard platnosc = createNewPayment(1, true, data, 1); 
     128            _rep.Insert(platnosc); 
     129 
     130            var controller = new PlatnoscController(fake); 
    105131            controller.UpdateStatus(1, "111");   //111 - płatność niepoprawna, ze wzgledu na zly numer karty 
    106132 
     
    108134            payment_after_update = _rep.FindOne(i => i.ORDERNUMBER == 1); 
    109135            Assert.That(payment_after_update.Status_data, Is.EqualTo(data)); 
    110  
    111         } 
    112          
    113         [Test] 
    114         [Category("Unit")] 
    115         public void NumerFaktury() 
     136        }         
     137        [Test] 
     138        [Category("Unit")] 
     139        public void TestFindInvoiceByNumber() 
    116140        { 
    117141             FakeDataContext fake = new FakeDataContext(); 
     
    124148        [Test] 
    125149        [Category("Unit")] 
    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); 
    139159            _rep.Insert(pl1); 
    140160 
     
    144164        [Test] 
    145165        [Category("Unit")] 
    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"); 
    162177             
     178            
    163179            var result = controller.Show("74828","pl") as ViewResult; 
    164180            var error = (ErrorViewData)result.ViewData.Model; 
    165181             
    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"); 
    187234 
    188235            var result = controller.Show("74828", "pl") as ViewResult; 
     236            Assert.IsInstanceOfType(typeof(InvoiceDetailsViewData), result.ViewData.Model); 
     237             
    189238            var view = (InvoiceDetailsViewData)result.ViewData.Model; 
    190  
    191239            Assert.That(view.vPlatnosciEcard.Brutto, Is.EqualTo(200)); 
    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 
    219256            controller.Show(payer, "pl"); 
     257 
    220258            Assert.That(controller.ModelState.IsValid, Is.False); 
    221259        } 
    222260        [Test] 
    223261        [Category("Unit")] 
    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");   
    247274            controller.Show(payer, "pl"); 
     275 
    248276            Assert.That(controller.ModelState.IsValid, Is.True);  
    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        }         
    275278        [Test] 
    276279        [Category("UI")] 
     
    281284            ie.TextField(Find.ByName("nip")).TypeText("501379568"); 
    282285            ie.Button(Find.ById("but")).Click(); 
    283  
    284286            Assert.IsTrue(ie.ContainsText("została uregulowana")); 
    285287        } 
     
    292294            ie.TextField(Find.ByName("nip")).TypeText(""); 
    293295            ie.Button(Find.ById("but")).Click(); 
    294  
    295296            Assert.IsTrue(ie.ContainsText("Logowanie nie powiodło się")); 
    296297        } 
  • trunk/eCard/eCardMVC/Platnosci/Controllers/PlatnoscController.cs

    r871 r872  
    2525        private readonly IRepository<PlatnosciEcard> _repPl; 
    2626        private FunkcjePlatnosci _func; 
    27         private string userIdentity = ""; 
    2827        private string weryfikacja = ""; 
    2928        private string brakdanych = ""; 
     
    3130        private string err_imie = ""; 
    3231        private string err_nazwisko = ""; 
    33          
    3432 
    3533        protected override void Initialize(System.Web.Routing.RequestContext requestContext) 
    3634        {             
    3735            base.Initialize(requestContext); 
    38             userIdentity = HttpContext.User.Identity.Name; 
    3936            weryfikacja = HttpContext.GetGlobalResourceObject("tlumaczenia", "weryfikacja").ToString(); 
    4037            brakdanych = HttpContext.GetGlobalResourceObject("tlumaczenia", "brakdanych").ToString(); 
     
    5249                       
    5350        } 
    54         public PlatnoscController(IDataContext datacontext){ 
     51        public PlatnoscController(IDataContext datacontext) 
     52        { 
    5553            _rep = new Repository<PotwierdzeniaEcard>(datacontext); 
    5654            _repPl = new Repository<PlatnosciEcard>(datacontext); 
    5755            _context1 = datacontext; 
    58             _func = new FunkcjePlatnosci();             
     56            _func = new FunkcjePlatnosci(); 
    5957        } 
    6058        public ActionResult Show(string id, string language) 
    6159        { 
     60           
    6261            language = _func.setLanguage(language); 
    63             string jezyk = Thread.CurrentThread.CurrentCulture.Name.ToString(); 
    6462            int id1 = 0; 
    6563            try 
     
    6967            catch 
    7068            { 
    71             } 
    72            
     69            }           
    7370            vPlatnosciEcard platnosc = _rep.FindInvoiceById(id1).SingleOrDefault(); 
    7471            ErrorViewData errorViewData = new ErrorViewData(); 
     
    7875               return View("Error1", errorViewData);                 
    7976            } 
    80             else if (!_func.UserIdentity(platnosc, userIdentity)) 
     77            else if (!_func.UserIdentity(platnosc, HttpContext.User.Identity.Name)) 
    8178            { 
    8279                errorViewData.error = weryfikacja; 
     
    9087                errorViewData.error = String.Format(zaplacono, platnosc.Faktura_Numer, data_zaplaty); 
    9188                return View("Error1", errorViewData); 
    92             } 
    93              
     89            }             
    9490            string kwota = ""; 
    9591            kwota = _func.BruttoToString(platnosc.Brutto, platnosc.waluta_brutto, platnosc.waluta_miano); 
     
    114110            ErrorViewData errorViewData = new ErrorViewData(); 
    115111 
    116             if (!_func.UserIdentity(platnosc, userIdentity)) 
     112            if (!_func.UserIdentity(platnosc, HttpContext.User.Identity.Name)) 
    117113            { 
    118114                errorViewData.error = weryfikacja; 
     
    124120                return View("Error1", errorViewData); 
    125121            } 
    126             else if (!_func.UserIdentity(platnosc, userIdentity)) 
     122            else if (!_func.UserIdentity(platnosc, HttpContext.User.Identity.Name)) 
    127123            { 
    128124                errorViewData.error = weryfikacja; 
     
    166162            if (platnosc == null) 
    167163            { 
    168                 errorViewData.error = HttpContext.GetGlobalResourceObject("tlumaczenia", "faktura_error").ToString(); 
    169                 return View("Error1", errorViewData); 
    170             } 
    171             else if (!_func.UserIdentity(platnosc, userIdentity)) 
     164                errorViewData.error = brakdanych; 
     165                return View("Error1", errorViewData); 
     166            } 
     167            else if (!_func.UserIdentity(platnosc, HttpContext.User.Identity.Name)) 
    172168            { 
    173169                errorViewData.error = weryfikacja; 
     
    247243            return invoiceDeatailsViewData; 
    248244        } 
    249         public void setUserIdentity(string value) 
    250         { 
    251             this.userIdentity = value; 
    252  
    253         } 
    254245        public void setWeryfikacja(string value) 
    255246        {