This web application was developed for an advanced Object-Oriented programming class. It utilized Microsoft’s .MVC framework and showed a comprehensive use of the MVC design pattern. The code for the frontend of the webapp was in HTML, and the backend code was in C#. Included in the solution for the project are several unit tests and an extensive repo class to handle coin management.
Users input a monetary value into the input box and click submit. Once they do so, the text underneath populates to reflect the value they put in and the least amount of US coins needed to represent said value.
Similar to the MVVM design pattern, the MVC design pattern separates application functionality between application logic, data, and the user interface. MVCs primary use case is in web app and website architecture. In this project, I used the MVC design pattern to separate the logic for calculating change from the view that displayed the amount of coins to the user.
The majority of the application's data functionality is from the CurrencyRepo class, which calculates which coins make up a monetary amount. This class inherited from an interface, ICurrencyRepo, which I created in order to use mock instances and substitute different implementations when necessary.
Shown below are some implementations of methods defined in ICurrencyRepo:
To keep in line with the encapsulation and single responsibility principles, the implementation for views remained strictly related to the appearance of the web app.
Below is the HTML for the "Make Change" view:
In this application, I used controllers to handle requests that were made through the website's interface. The controllers updated their corresponding view models, which the views were connected to by data binding. The "Make Change" controller, which is invoked when the submit button is pressed, returns an updated version of the view (described above) to the browser.
Below is the controller for the "Make Change" page:
I designed Unit Tests to verify that model behavior was working as expected, as these models were also used for XAML and console applications. By testing the models by themselves, I ensured that any errors in behavior were caused by functionality specific to the kind of application I was making. I used Moq to create mock instances of the ICoin and ICurrencyRepo classes, which allowed for lightweight testing.
Here are some of the Unit Tests for the currency repo class: